Jump to content

Form Validation


dbo

Recommended Posts

Ever get annoyed spending 90% of your time validating user input before processing/inserting into a database? I know I do. I was thinking of trying to write some framework that makes this process more generic and reusable. I'd also like to be able to share the same validation rules with javascript so that I don't have to write the logic twice. I was thinking define some sort of XML document with my validation rules and share that between PHP & Javascript but I see some limitations there as well.

 

So my questions to you, fellow PHPers, do you see merit in this idea? Is it reinventing the wheel... what might be some existing solutions or frameworks that would be worth looking into?

 

Thanks,

-Derek

Link to comment
https://forums.phpfreaks.com/topic/60771-form-validation/
Share on other sites

Oh I'm not doing it to try and sell or make money off of. Not the framework at least. It's just part of a larger project and I want something to be robust to make my life easy so like I could say.

 

//THIS IS A GENERIC EXAMPLE...

if( isset($_POST['button1']) )

{

  $field1 = $_POST['field1'];

  $field2 = $_POST['field3'];

  $field3 = $_POST['field4'];

 

  $arr = Array($field1, $field2, $field3);

 

  $is_valid = validate($arr, "form.xml");

}

 

and then on down the page i could say.

 

generate_javascript_validation("form.xml");

 

or something to that affect.

Link to comment
https://forums.phpfreaks.com/topic/60771-form-validation/#findComment-302390
Share on other sites

My approach works fine for "normal" cases, but if I have a situation where lets say a delivery date has to happen between 2 weeks of a start date I've got to know that start date before I can do the validation. This can't be a hard coded value in an XML file.

 

Any thoughts... alternative approaches?

Link to comment
https://forums.phpfreaks.com/topic/60771-form-validation/#findComment-302427
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.