PHP Classes

Form Data Validator: Validate submitted form input values

Recommend this page to a friend!
  Info   View files Example   Demos   Screenshots Screenshots   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 534 All time: 5,619 This week: 107Up
Version License PHP version Categories
form-data-validator 1.0GNU General Publi...5.2HTTP, PHP 5, Validation
Description 

Author

This class can validate submitted form input values.

It can take an array with accepted form inputs and required inputs and validates a given $_POST or $_GET array with submitted form values.

The class returns an array with validated form values and validation errors.

Picture of Nemeth Zoltan
  Performance   Level  
Name: Nemeth Zoltan is available for providing paid consulting. Contact Nemeth Zoltan .
Classes: 9 packages by
Country: Hungary Hungary
Age: 46
All time rank: 157113 in Hungary Hungary
Week rank: 344 Up4 in Hungary Hungary Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<h3>Simple validator class for form data</h3>
<?php
/*
 * Teszt for FormDataValidator class
 */
if (isset($_POST) && count($_POST) > 0) {
  echo
"<pre>Validation start.<hr>POST data<br>---<br>";
 
var_export($_POST);
  require_once
'formDataValidator.class.php';
 
$accepted = array('name', 'nick', 'email', 'message');
 
$required = array('name', 'nick', 'message');
 
$validator = new FormDataValidator($_POST, $accepted, $required);
 
$resp = $validator->validate();
  echo
"<br>After validation<br>";
 
var_export($resp);
  echo
"</pre>";
}

 
?>
<p>Please fill and put the following form:</p>
  <form method="post" action="index.php">
    Name*: <input type="text" name="name" value="<?php print trim($_POST['name']); ?>" /><br>
    Nick: <input type="text" name="nick" value="<?php print trim($_POST['nick']); ?>" /><br>
    E-mail*: <input type="text" name="email" value="<?php print trim($_POST['email']); ?>" /><br>
    Message*: <input type="text" name="message" value="<?php print trim($_POST['message']); ?>" /><br>
    Not accepted: <input type="text" name="sample" value="<?php print trim($_POST['sample']); ?>" /><br>
    <input type="submit" value="Send"/>
  </form>


Screenshots  
  • sample_output
  Files folder image Files  
File Role Description
Plain text file formDataValidator.class.php Class The main class
Accessible without login Plain text file index.php Example Test file for the class
Accessible without login Plain text file output.txt Output Sample output from index.php

 Version Control Unique User Downloads Download Rankings  
 0%
Total:534
This week:0
All time:5,619
This week:107Up
User Comments (2)
Provides a good validation class skeleton.
9 years ago (J Diamond)
70%StarStarStarStar
This is a good and useful class :-)
9 years ago (Josť Filipe Lopes Santos)
55%StarStarStar