Jump to content
Larry Ullman's Book Forums

Multiple Form Validation - Possible Create One Function?


Recommended Posts

Hi,

 

I am trying to come up with a way to validate multiple forms with ONE validation file or function.

 

Problem is each form would have different fields, some maybe same, and could be empty.

 

I was thinking of doing a check of isset and not empty before allowing validation of each field but what happens if a particular field is empty but is required?

 

I am using an altered form_functions.inc.php file, it is essentially same as in book but added a few field types that weren't in there, checkbox, radio fields etc...

 

I would like to simplify the validations into a function or altered validation.php file that gets included on each form page but I am having difficulty thinking through the logic on this. I just want fields that exist on the form to be validated and those that don't exist get by passed and NO error gets returned if the validation code thinks it should exist and is just empty when in fact that field does not exist on the form at all.

 

I am trying to prevent creating seperate validation pages for each form, just do it all in one place that gets called and handles all validation no matter what type of form or fields exist.. eg: registration, login, questionaire, poll, profile pages or what have you.

 

Maybe there is an obvious way here I am just not seeing it right now.

 

Thanks for any help.

Link to comment
Share on other sites

What you would have to do is create an array of validation options for each form element. Those options would include: form element name, required, min, max, type, etc. Then you'd write a function that parsed the array and performed the proper validation according to the various values.

Link to comment
Share on other sites

 Share

×
×
  • Create New...