PHP Developers Network
http://forums.devnetwork.net/

php validation
http://forums.devnetwork.net/viewtopic.php?f=1&t=139986
Page 1 of 1

Author:  chris93 [ Fri Aug 01, 2014 6:08 pm ]
Post subject:  php validation

Syntax: [ Download ] [ Hide ]
<?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);

?>


when i run this code im getitng


Parse error: syntax error, unexpected ',' in C:\xampp2\htdocs\tutorials\forms\form4.php on line 47

Author:  Celauran [ Fri Aug 01, 2014 8:27 pm ]
Post subject:  Re: php validation


Author:  pbs [ Mon Aug 04, 2014 8:08 am ]
Post subject:  Re: php validation

replace this with 47 line number

Syntax: [ Download ] [ Hide ]
$request = (get_magic_quotes_gpc() ? array_map('stripslashes', $_REQUEST) : $_REQUEST);

Author:  Celauran [ Mon Aug 04, 2014 8:11 am ]
Post subject:  Re: php validation

Note that as of PHP 5.4, get_magic_quotes_gpc always returns false.

Author:  KarlRice [ Mon Aug 11, 2014 11:12 pm ]
Post subject:  Re: php validation

The PHP Validation script is a set of validation rules which lets you add server-side validation to your forms quickly and with as little effort as possible.

We’ll go into more detail in the later pages – this page is mainly just to give you a general sense of how it fits together.
1. Download and upload the PHP validation script (validation.php) to your web server and include() or require() that file via PHP in your form page. Note: your form will need to be a .php page.
2. Direct your form to submit its contents to itself using the action=”” attribute. When the form successfully passes your validation rules, you can redirect via PHP to whatever page you want the user to see next. If it fails, you can output the errors directly in the form page for the user to fix.
3. Add your form-specific validation rules to the top of your form page before the opening tag. These validation rules are basically a LIST (or an array for the technically-literate), saying which form fields need to validated, in what way, and what errors should be displayed to the user if they’re not filled in properly.
4. Add some display code into your page which will output any errors that occur.

Author:  Celauran [ Tue Aug 12, 2014 7:20 am ]
Post subject:  Re: php validation


Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/