The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
use validation only if ... - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8) +--- Forum: Form Validation: JS + PHP (https://forums.formtools.org/forumdisplay.php?fid=18) +--- Thread: use validation only if ... (/showthread.php?tid=231) |
use validation only if ... - Alexis - Aug 6th, 2009 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 RE: use validation only if ... - Ben - Aug 6th, 2009 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 = []; 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. - Ben RE: use validation only if ... - Alexis - Aug 7th, 2009 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 |