PDA

View Full Version : نمایش کادر خطا برای خالی بودن فیلد در فرم ! کمک !



mehdi king
دوشنبه 27 آذر 1391, 15:37 عصر
سلام

اساتید محترم

من یک اسکریپت برای پایان نامه دارم انجام میدم درست میکنم

که میخوام برای ثبت اطلاعات در دیتابیس که فرمی قرار داره اگر فیلد یا همون تکست باکس ما خالی بود کادر خطا باز بشه و پیغام مورد نظر رو بده ..

برای هر تکست باکس که خالی بشه چطوری میتونم یک پیغام درنظر بگیرم ؟؟

و اگر هم درست بود و پر بود ثبت بانک بشه .

من با DW درست کردم ثبت بانک هم میشه و به جا کادر خطا صفحه رو سفید با یک خطا میده ....

آیا خود DreamWeare امکانی نداره بشه باش واسه خالی بودن تکست باسا الردی داد ؟

اگه نیست چطوری درست کنم ؟

این کد صفحه منه


<?php require_once('../Connections/cn.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="admin-edit-rt.php";
$loginUsername = $_POST['karbari'];
$LoginRS__query = sprintf("SELECT karbari FROM modir WHERE karbari=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_cn, $cn);
$LoginRS=mysql_query($LoginRS__query, $cn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);

//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO modir (nam, famil, karbari, ramz, email) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['nam'], "text"),
GetSQLValueString($_POST['famil'], "text"),
GetSQLValueString($_POST['karbari'], "text"),
GetSQLValueString($_POST['ramz'], "text"),
GetSQLValueString($_POST['email'], "text"));

mysql_select_db($database_cn, $cn);
$Result1 = mysql_query($insertSQL, $cn) or die(mysql_error());

$insertGoTo = "admin-edit-ok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_cn, $cn);
$query_rs1 = "SELECT * FROM modir";
$rs1 = mysql_query($query_rs1, $cn) or die(mysql_error());
$row_rs1 = mysql_fetch_assoc($rs1);
$totalRows_rs1 = mysql_num_rows($rs1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/template.css" rel="stylesheet" type="text/css" />
<title>OnlineOff | ویرایش مدیر سایت</title>
</head>

<body>
<div class="body">
<div class="top_menu"></div>
<div class="center_menu">
<div class="header"></div>
<div class="date">
<div class="tab">
<table width="419" height="46" border="0">
<tr>
<td width="416" valign="middle"><marquee scrollamount="3" direction="right">
قسمت افزودن . ویرایش و حذف مدیران سایت
</marquee></td>
</tr>
</table>
</div>
</div>
<div class="table">
<table width="1052" border="0">
<tr>
<td width="261" valign="top"><table width="241" border="0" cellspacing="10">
<tr>
<td align="center" valign="top">
<div class="topmenu"></div>
<div class="centermenu">
<div class="sp2"><font color="#003300"><?php echo $_SESSION['MM_Username'] ?> خوش آمدید</font><br />
<br />
<a href="<?php echo $logoutAction ?>">خروج</a> | تغییر رمز عبور </div>
</div>
<div class="bottommenu"></div>
</td>
</tr>
<tr>
<td align="center" valign="top">
<div class="topmenu"></div>
<div class="centermenu">
<div class="sp2"><font color="#FF0000">راهنما صفحه:</font>
<hr />
در این صفحه شما میتوانید<br />
مدیر به سایت اضافه و <br />
ویرایش و یا مدیر سایت را<br />
حذف کنید <br />
<br />
برای ویرایش مدیر روی مداد در<br />
ردیف آن مدیر و<br />
برای حذف مدیر روی ضربدر<br />
در ردیف آن مدیر کلیک نمایید .
<br />
</div>
</div>
<div class="bottommenu"></div>
</td>
</tr>
<tr>
<td align="center" valign="top"> <div class="topmenu"></div>
<div class="centermenu">
<div class="sp2"><font color="#FF0000"><a style="text-decoration:none" href="admin-cp.php">بازگشت به صفحه اصلی مدیریت</a></font></div>
</div>
<div class="bottommenu"></div></td>
</tr>
</table></td>
<td width="781" align="left" valign="top"><table width="773" border="0" cellspacing="10">
<tr>
<td width="751" align="center" valign="top">
<div class="topcen"></div>
<div class="centercen">
<div class="sp1">افزودن مدیر جدید :<br />
<br />
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">نام :</td>
<td><input type="text" name="nam" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">نام خانوادگی :</td>
<td><input type="text" name="famil" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">نام کاربری :</td>
<td><input type="text" name="karbari" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">رمز عبور :</td>
<td><input type="password" name="ramz" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ایمیل :</td>
<td><input type="text" name="email" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="left" valign="middle" nowrap="nowrap"><input type="submit" value=" افزودن مدیر جدید " /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form><br /><br /><hr /><br />
ویرایش یا حذف مدیر : <br />
<br />
<table width="691" border="0" cellspacing="3" background="images/bgtaadmin.png">
<tr>
<td width="83" height="23px" align="center">نام :</td>
<td width="162" align="center">نام خانوادگی :</td>
<td width="136" align="center">نام کاربری :</td>
<td width="186" align="center">ایمیل :</td>
<td width="42" align="center">ویرایش</td>
<td width="42" align="center">حدف</td>
</tr>
<?php do { ?>
<tr>
<td align="center" valign="middle"><?php echo $row_rs1['nam']; ?></td>
<td align="center" valign="middle"><?php echo $row_rs1['famil']; ?></td>
<td align="center" valign="middle"><?php echo $row_rs1['karbari']; ?></td>
<td align="center" valign="middle"><?php echo $row_rs1['email']; ?></td>
<td align="center"><a href="admin-editing.php?id=<?php echo $row_rs1['id']; ?>"><img src="images/edit.png" width="23" height="23" border="0" /></a></td>
<td align="center"><a href="admin-deleting.php?id=<?php echo $row_rs1['id']; ?>"><img src="images/del.png" width="23" height="23" border="0" /></a></td>
</tr>
<?php } while ($row_rs1 = mysql_fetch_assoc($rs1)); ?>
</table>
</div>
</div>
<div class="bottomcen"></div>
</td>
</tr>
</table></td>
</tr>
</table>
</div>
<div class="foter"></div>
</div>
<div class="bottom_menu"></div>
</div>
</body>
</html>
<?php
mysql_free_result($rs1);
?>


و یک سوال یگه !!! میخواهم اگر توی تکست باکس مخصوص ایمیل فورمت ایمیل ننوشته بود اخطار بده که باید ایمیل بنویسی


ممنون از شما

فرزند کوروش
دوشنبه 27 آذر 1391, 16:08 عصر
if($_POST['feildname'] == '' ){
echo 'فیلدهای ستاره دار کامل شود';
}else{

//کدهای مربوط به اینسرت در جدول
}

siavashsay
دوشنبه 27 آذر 1391, 16:43 عصر
دوست عزیز !
اگر شما میخواید که همون لحظه اگر کاربر فیلد رو خالی رها کرد و به فیلد بعدی رفت باید از جاوا استفاده کنید !
توی خود برنامه DW 3 تا تب بعد از تب Form تبی به نام SPRY هست ! بجای فیلدهای معمولی در فرم از اون فیلد ها استفاده کنید !
البته فقط به این فیلدها متکی نشید ! چون چک کردن جاوا در سمت کلاینت هست و حتما باید در سمت سرور هم چک بشه !
برای چک کردن فیلدها در سمت سرور از نمونه کدی که دوستمون دادن استفاده کنید ! :)