We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13740
    • 86 Posts
    Can eform require a field to be filled in based on the value of another field?
    eg One question is radio buttons asking if you require a parking space. If yes, I want the field for license plate number to be required.
      • 10534
      • 40 Posts
      You can achieve this with custom validation function.

      See this example:
      set the radio required (eform="Parking space::1" in input), and then on the license plate input this:
      eform="License plate::1:You want some parking space; please fill in your license plate:#FUNCTION checkLicenseplate"

      and than make snippet with the function "checkLicenceplate", wich you include in the same page as the eform snippetcall, let’s say [!eFromExtrafunctions!]:
      function checkLicenseplate( &$value ){
          if( isset($_POST['parking']) && ($_POST['parking'] == "yes") ){
              //parking set to yes: licenseplate required, check for REAL value
              if($value != " " )
                  return true;
              else return false;
          }
          //parking set to no: licenseplate not required, set to TRUE!
          else return true;
      }
      


      As you can see, I check to see whether the parkingspace input is not " " (see the space); What you do is set the value of the licenseplate to 1 single space with an onfocus="this.select()", otherwise eForm will inform you that a value is required, even if a parking space is not required. You cannot turn ’required’ off ("License plate::0:.....) and have the extra functionality with the new function. If it is not filled, it will remain a space and therefore faulty when parking space is checked.

      Hope you follow this...

      I anybody alse has a better solution, I’d like to hear it too!