Sunday, 31 July 2016

PHP class for form validation

  No comments

PHP plays great role in the form values sensitization. PHP provide filters with the help of that you plays with form validation & sensitization of form values. PHP provides three types of filter which is below.

  •  Validate filters

  •  Sanitize filters

  •  Other filters

Validate filters
PHP provide in built function for some values validate like email, url, IP address, int , float & regx validation.
for more information

Sanitize filters
Sanitize filters are used for making valid input so that in future it will create the hole in application. With maintian validation user can be input such a values that can break the functionlity like not inserted in the database or can input the code that can be used in the future. So Sanitize filters can be filter the user inputs.

Other filters
PHP faciliate to developer he can be add our custom function. That function can be call at time of validation.

So with the usage of these function ii try to create  a class that can be used for validation form. The class that i have written in which covered the below validation.

  • Email validation

  • Required validation

  • Numeric validation

  • positive numeric validation

  • positive integer validation

  • URL

  • Alpha

  • Alphanumeric

  • Unique value in database

  • two parameter field value comparison

  • Max & Min character limit

  • Photos

  • upload validation

So below i will show you structure of the class how to be processed. We cretae the seprate function each above validation. which is shown to you in below code.

Now show to how to be use this class. So need to initiliaze the array in which we pass the parameter on which class validation working. For different validation how to call. In below code first need to initiliaze the array. Then provide the one dimensional array to validate for array variable [array_to_validate]. Then just pass the element name from there class get the values. For example [$config['email']] assign account_email, alternative_email textbox name so that it can be validate.

No comments :

Post a Comment