The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.28 (Linux)
|
Pulldown to trigger Text field - 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: Pulldown to trigger Text field (/showthread.php?tid=2694) |
Pulldown to trigger Text field - MHarrison - Sep 22nd, 2013 Hi guys, Hope you can enlighten me. I have a Pulldown field with 6 values, "0" to "5", with an adjacent Text field for comments. I need to require the comment field be filled out only when the value of the Pulldown is 0, 1, or 2. This is what I've come up with so far: Code: rules.push("required,element_9,Please select an Sportsmanship Rating."); This is the first instance of 20 such instances on the form, which has worked with all fields simply "required." With this code on the form, the error reporting gets truncated to an error that is always and only about the element_10B field regardless of how the form is filled out. I started with this example code as a template: Code: [if:FIELDNAME=VALUE,]REQUIREMENT,fieldname[,fieldname2[,fieldname3,date_flag]],error message" but something seems to be missing. I thought I would be validating based on the "range=X-Y" requirement, but I don't see where it belongs in the code. Could you point me in the right direction? Much appreciated, Mark Harrison RE: Pulldown to trigger Text field - MHarrison - Sep 23rd, 2013 Hi folks, Making some progress, but have run into unexpected behavior. As stated before, choosing "0" "1" or "2" should then require the adjacent comment field to be required. I tried setting "range=0-2" in the following code and the error message was triggered on 3, 4, or 5. So I swapped the range to get the desired behavior. Looks like this: Code: rules.push("required,element_9,Please select an Sportsmanship Rating."); Easy enough, but possibly highlights a bug in this range validation function, or am I missing something? Moving on, I then tried to add this line: Code: rules.push("if:range=3-5,element_9,required,element_9B,Please enter an Sportsmanship Comment."); which breaks the form and prints "process.php" to the browser window for any value, 0-5. Can anyone help me out with this problem? Much appreciated, Mark Harrison RE: Pulldown to trigger Text field - MHarrison - Sep 23rd, 2013 Hi folks, Now it appears my original code was correct as it now works. Go figure. Code: rules.push("required,element_9,Please select an Sportsmanship Rating."); Thanks for the sounding board. Regards, Mark Harrison |