php validation
Posted: Fri Aug 01, 2014 6:08 pm
Code: Select all
<?php
ob_start();
?>
<html>
<head>
<title>fillInFormValues: short example</title>
<style>
.error { color: red; }
</style>
</head>
<body>
<h1>Sign up for our newsletters</h1>
<ul class="error"><li>PLACEHOLDER FOR FORM ERRORS</li></ul>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<table border="0">
<tr>
<td><label for="email">Your Email Address:</label></td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td><label for="newsletter">Sign up for these newsletters:</label></td>
<td>
<input type="checkbox" name="news" id="news">
<label for="news">News</label><br />
<input type="checkbox" name="security" id="security">
<label for="security">Security Notices</label><br />
<input type="checkbox" name="specials" id="specials">
<label for="specials">Specials</label>
</td>
</tr>
<tr><td> </td>
<td><input type="submit" name="submit" value="Sign Up"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$html = ob_get_contents();
ob_end_clean();
require_once("fillInFormValues.php");
require_once("validateForm.php");
$request = (get_magic_quotes_gpc() ?
array_map('stripslashes', $_REQUEST), $_REQUEST);
$validationData['email'] = array('isRequired', 'type' => 'email');
if (isset($request['submit'])) {
$formErrors = validateForm($request, $validationData);
if (count($formErrors) == 0) {
// Normally there would be code here to process the form
// and redirect to a thank you page...
// ... but for this example, we just always re-display the form.
$info = "No errors; got these values:".
nl2br(htmlspecialchars(print_r($request, 1)));
$html = preg_replace('/<body>/', "<body><p>$info</p>", $html);
}
}
else {
$formErrors = array();
}
echo fillInFormValues($html, $request, $formErrors);
?>Parse error: syntax error, unexpected ',' in C:\xampp2\htdocs\tutorials\forms\form4.php on line 47