FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use validation only if ...
#1
Hello

what i would love to do is to validate the form only if the user has selected "validate the form"

i'd like to have a select with 2 options
Validate the form
Save data without validating.

if the user selects save w/o validating it just sends the form
if he selects validate the form it calls the validate script

any ideas on how to do this ?

thanks

alex
Reply
#2
Hi Alex,

Sure! The simplest way to do it would be to just add a pair of radio buttons like so:

Code:
Validate form? (x) Yes ( ) no

Then add an "if:" clause to the beginning of all your JS validation rules that tell it to only run that validation if the validate field == "yes", (I'm assuming the name attribute of the radio buttons is "validate"), e.g.

Code:
var rules = [];
rules.push("if:validate=yes,required,field1,Please fill in field 1.");
rules.push("if:validate=yes,required,field2,Please fill in field 2.");
...

Then, on the backend, you could do something similar: just check that the incoming $_POST["validate"] == "yes" and then run the rules.

Hope this helps a bit. Smile

- Ben
Reply
#3
oh my god!
i was googling until 2am yesterday to find how to include the js with ajax or something complicated

your solution works perfectly
thanks for your scripts, they're just great
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)