The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
conditional validation - 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: conditional validation (/showthread.php?tid=1562)



conditional validation - egeller624 - Aug 26th, 2011

I have 3 separate radio buttons in my form with possible answers of "yes" or "no". I would like to make a text field required only if one or more of the radio buttons has been set to "yes" but I can't seem to figure out how to do that. This is what I tried so far but it's not working:

Code:
rules.push("if:c1_allergies=yes||c1_medical=yes||c1_medications=yes,required,Please provide medical details.");

The conditional validation works fine for a simple if condition but what is the syntax for more complex logic like this? Or would I be better off with a separate function?

Thanks.


RE: conditional validation - Ben - Aug 26th, 2011

Hi egeller,

Good question. The conditional logic for the RSV library is REALLY basic. I just added it because simple "if A=X then validate B" logic was common and wanted to cover that scenario with some simple syntax. In your case, it's a bit more complex so you'll need to use a custom function instead. For that, try something like this:

Code:
rules.push("function,mycustomfunction");
function mycustomfunction() {
  if ( ... c1_allergies=yes||c1_medical=yes||c1_medications=yes ... ) {
    if ( ... c1_medications != "yes" ... ) {
      return [[ *c1_medications DOM element * , "Please provide medical details."]];
    }
  }

  return true;
}

You will need to replace the if conditions with whatever code makes sense, depending on the field types. Sorry - that will take a little JS knowledge, but feel free to post back if you're not sure about it.

Also the return statement will need to return the c1_medications DOM element as the first parameter.

For more info, check out the "Custom Validation Rules" page in the help doc:
http://www.benjaminkeen.com/software/rsv/standalone/

Good luck! Smile

- Ben


RE: conditional validation - egeller624 - Aug 27th, 2011

Thanks for the reply, it works a treat! Just had to refresh my memory on JS syntax Wink