VivekMishra

How to use the validation function

<? require_once(‘includes/validation.php’);
function displayErrors($errors) {
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
{
echo “<div class=’errors’><p><em>Oops… the following errors were encountered:</em></p>\n<ul>”;
foreach ($errors as $error) {
echo “<li>$error</li>\n”;
}
echo “</ul><p>Data has <strong>not</strong> been saved.</p></div>”;

$_SESSION[‘errors’] = array();
}
}

$errors = array();
if (isset($_POST[‘submit’])) {
$rules = array(); // stores the validation rules

$rules[] = “required,username,Username is required.”;
$rules[] = “required,password,Password is required.”;

$errors = validateFields($_POST, $rules);

// Check given email id is already exist or not.
if (isset($_POST[‘username’]) && $_POST[‘username’] != ” && empty($errors)) {
if (validateLogin($_POST[‘username’], $_POST[‘password’])) {
header(‘Location: mainpage.php’);
}
else {
$errors[] = “The username and password do not match. Please try again.”;
}
}

}
?>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>

<tr>
<td align=”center” valign=”middle”><table width=”475″ border=”0″ cellspacing=”0″ cellpadding=”0″ id=”Login”>
<tr>
<td align=”center”>
<?php displayErrors($errors);?>        </td>
</tr>
<tr>
<td align=”center” valign=”top” class=”middle”><form action=”index.php” method=”post”>
<table width=”450″ border=”0″ cellspacing=”2″ cellpadding=”0″ id=”inner”>
<tr>
<td colspan=”2″ align=”center” valign=”middle”><h3>Please Sign-in to Admin Panel</h3></td>
</tr>
<tr>
<td width=”119″ align=”right” valign=”middle”>Username:</td>
<td width=”345″ align=”left” valign=”middle”><label>
<input type=”text” name=”username” maxlength=”127″ size=”40″ value=”<?=$username?>”>
</label></td>
</tr>
<tr>
<td align=”right” valign=”middle”>Password:</td>
<td align=”left” valign=”middle”><input type=”password” name=”password” size=”40″ maxlength=”40″ value=”<?=$password?>”></td>
</tr>
<tr>            </tr>
<tr>
<td align=”right” valign=”middle”>&nbsp;</td>
<td align=”left” valign=”middle”><input name=”submit” type=”submit” class=”button” value=”Sign In” /></td>
</tr>
<tr>            </tr>
<tr>
<td align=”right” valign=”middle”>&nbsp;</td>
<td align=”left” valign=”middle”>&nbsp;</td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td class=”bottom”>&nbsp;</td>
</tr>
</table></td>
</tr>
</table>

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


  • None
  • Mr WordPress: Hi, this is a comment.To delete a comment, just log in, and view the posts' comments, there you will have the option to edit or delete them.

Categories

%d bloggers like this: