PHPackages                             jasonsarino/php-formvalidator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. jasonsarino/php-formvalidator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

jasonsarino/php-formvalidator
=============================

2.1(5y ago)010PHP

Since Dec 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jasonsarino/php-formvalidator)[ Packagist](https://packagist.org/packages/jasonsarino/php-formvalidator)[ RSS](/packages/jasonsarino-php-formvalidator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (8)Used By (0)

PHP Formvalidator
=================

[](#php-formvalidator)

This library use to validate and sanitize form entry with sanitization to avoid sql injection and easy to set rules for specific fields.

Install
-------

[](#install)

```
composer require jasonsarino/form-validator

```

#### Requires PHP 7.1 or newer.

[](#requires-php-71-or-newer)

Usage
-----

[](#usage)

#### Include Sanitizer and FormValidator Class

[](#include-sanitizer-and-formvalidator-class)

```
// include sanitizer class
require_once 'Sanitizer.php';

// include formvalidator class
require_once 'FormValidator.class.php';

// init class
$form = new FormValidator();

```

### Fetch data from $\_POST form

[](#fetch-data-from-_post-form)

assume that we have data from $\_POST data

```
// Fetch value from post type
$_POST['firstname'] = "Juan";
$_POST['surname'] = "Dela Cruz";
$_POST['age'] = "23";
$_POST['comment'] = "This is test comment's";

```

### Reset data array for multiple form entries

[](#reset-data-array-for-multiple-form-entries)

(Optional) Use to reset array to FormValidator class f you have multple form entries

```
$form->data = array();

```

### Set and Hold $\_POST into data array variable

[](#set-and-hold-_post-into-data-array-variable)

```
$form->setData($_POST);

```

### Set Rules ro fields

[](#set-rules-ro-fields)

```
// set rules for First Name
$form->setRules('firstname','First Name','required|alphaS');

// set rules for Surname
$form->setRules('surname','Surname','required|alphaS');

// set rules for Age
$form->setRules('age','Age','required|num');

// set rules for Comment
$form->setRules('comment'  , 'Comment',   'alphaNumSymbolS');

```

### Validate data array variable with rules

[](#validate-data-array-variable-with-rules)

```
$form->validateData();

```

### Get the result from validateData method

[](#get-the-result-from-validatedata-method)

return bolean

```
$form->isValid();

```

### Display Error

[](#display-error)

```
$form->getErrorMessage();

```

### Complete Usage

[](#complete-usage)

```
// include sanitizer class
require_once 'Sanitizer.php';

// include formvalidator class
require_once 'FormValidator.class.php';

// init class
$form = new FormValidator();

// Fetch value from post type
$_POST['firstname'] = "Juan";
$_POST['surname'] = "Dela Cruz";
$_POST['age'] = "23";
$_POST['comment'] = "This is test comment's";

/*
 * (Optional)
 * Use to reset array to FormValidator class
 * if you have multple form entries
 */
$form->data = array();

// Set and Hold data into array
$form->setData($_POST);

// set rules for First Name
$form->setRules('firstname','First Name','required|alphaS');

// set rules for Surname
$form->setRules('surname','Surname','required|alphaS');

// set rules for Age
$form->setRules('age','Age','required|num');

// set rules for Comment
$form->setRules('comment'  , 'Comment',   'alphaNumSymbolS');

// Execute and validate data request rules
$form->validateData();

// Check if valid all rules
if ($form->isValid()) {

    // Get sanitized $_POST from validator
    $firstname = $form->dataFields['firstname'];
    $surname = $form->dataFields['surname'];
    $age = $form->dataFields['age'];
    $comment = $form->dataFields['comment'];

    // Display $_POST data
    echo "First Name: " . $firstname . "Surname: " . $surname . "Age: " . $age . "Comment: " . $comment;

} else {

    // Display all errors.
    echo  $form->getErrorMessage();
}

```

Rule Reference
--------------

[](#rule-reference)

The following is a list of all the native rules that are available to use:

RuleParameterDescriptionExamplerequiredNoReturns FALSE if the form element is empty.alphaNoReturns FALSE if the form element contains anything other than alphabetical characters.alphaSNoReturns FALSE if the form element contains anything other than alpha characters or spaces. Should be used after trim to avoid spaces at the beginning or end.alphaNumNoReturns FALSE if the form element contains anything other than alpha-numeric characters.alphaNumSNoReturns FALSE if the form element contains anything other than alpha-numeric characters or spaces. Should be used after trim to avoid spaces at the beginning or end.alphaNumSymbolNoReturns FALSE if the form element contains anything other than alpha-numeric-symbol characters. Should be used after trim to avoid spaces at the beginning or end.alphaNumSymbolSNoReturns FALSE if the form element contains anything other than alpha-numeric-symbol characters or spaces. Should be used after trim to avoid spaces at the beginning or end.dateFormatNoReturns FALSE if the form element contains anything other than date format.dateTimeFormatNoReturns FALSE if the form element contains anything other than date and time format.emailNoReturns FALSE if the form element does not contain a valid email address.ipAddressNoReturns FALSE if the supplied IP address is not valid. Accepts an optional parameter of ‘ipv4’ or ‘ipv6’ to specify an IP format.maxLenYesReturns FALSE if the form element is longer than the parameter value.maxLen\[12\]numNoReturns FALSE if the form element contains anything other than numeric characters.numSNoReturns FALSE if the form element contains anything other than numeric and space characters.floatNoReturns FALSE if the form element contains anything other than a float number.regxpYesReturns FALSE if the form element not meet a particular regular expression.regxp\[/^\[0-9a-zA-Z \]+$/\]

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

1971d ago

Major Versions

1.0.4 → 2.02020-12-21

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

1.0.2PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/4231e434ea72dbcb4f27c4c6ca7c0391389393e5aad612acfc48c845c9198f05?d=identicon)[jasonsarino27](/maintainers/jasonsarino27)

---

Top Contributors

[![jasonsarino](https://avatars.githubusercontent.com/u/8446520?v=4)](https://github.com/jasonsarino "jasonsarino (28 commits)")

### Embed Badge

![Health badge](/badges/jasonsarino-php-formvalidator/health.svg)

```
[![Health](https://phpackages.com/badges/jasonsarino-php-formvalidator/health.svg)](https://phpackages.com/packages/jasonsarino-php-formvalidator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
