PHP Classes

Form Data Validator: Validate submitted form input values

Recommend this page to a friend!
  Info   Example   Demos   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 535 All time: 5,623 This week: 455Up
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 <contact>
Classes: 9 packages by
Country: Hungary Hungary
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 (1)  
  • sample_output
  Files folder image Files (4)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:535
This week:0
All time:5,623
This week:455Up
User Comments (2)
Provides a good validation class skeleton.
10 years ago (J Diamond)
70%StarStarStarStar
This is a good and useful class :-)
10 years ago (José Filipe Lopes Santos)
55%StarStarStar