PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu May 28, 2020 9:50 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: php validation
PostPosted: Fri Aug 01, 2014 6:08 pm 
Offline
Forum Newbie

Joined: Fri Aug 01, 2014 4:43 pm
Posts: 10
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


Last edited by Celauran on Fri Aug 01, 2014 8:25 pm, edited 1 time in total.
Please wrap your code in syntax tags.


Top
 Profile  
 
 Post subject: Re: php validation
PostPosted: Fri Aug 01, 2014 8:27 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada


Top
 Profile  
 
 Post subject: Re: php validation
PostPosted: Mon Aug 04, 2014 8:08 am 
Offline
Forum Contributor

Joined: Fri Nov 07, 2008 6:31 am
Posts: 230
Location: Nashik, India
replace this with 47 line number

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

_________________
|


Top
 Profile  
 
 Post subject: Re: php validation
PostPosted: Mon Aug 04, 2014 8:11 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Note that as of PHP 5.4, get_magic_quotes_gpc always returns false.


Top
 Profile  
 
 Post subject: Re: php validation
PostPosted: Mon Aug 11, 2014 11:12 pm 
Offline
Forum Newbie

Joined: Sun Aug 10, 2014 11:16 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: php validation
PostPosted: Tue Aug 12, 2014 7:20 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group