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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.