We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6725
    • 12 Posts
    Hi all,

    Like the topic says, I’ve had a problen using a #FUNCTION validate with a <select> in eForm. I’ve had a look around, but cannot seem to find a solution!

    		
    <select name="Trading" id="cfTradingTime" eform="How long have you been trading::1:You need to have been trading for more than 1 year:#FUNCTION checkFieldTradingTime"/>
    	<option value="None selected" selected="selected">Select from ...</option>
    	<option value="Start Up (0 - 3 months)">Start Up (0 - 3 months)</option>
    	<option value="3 months to 1 year">3 months to 1 year</option>
    	<option value="1 to 5 years">1 to 5 years</option>
    	<option value="5 years plus">5 years plus</option>
    </select>
    


    The php function (checkFieldTradingTime) simply returns a true / false depending on the value of the option selected. But from what I’ve discovered the function isn’t actually even being called. I have been successfully calling other #FUNCTION ’s from text and textarea inputs to validate the contents of the $value but never successful on a <select>.

    Any idea why ?

    Thanks in advance,
    David
      • 30223
      • 1,010 Posts
      Can you set the &debug parameter to 1 and then submit the form without any values entered? Then look at the debug info for the Formats Array.
      For your Trading field it should show the validation rule
      #FUNCTION checkFieldTradingTime
      but I suspect it will be something like
      #LIST None selected, Start Up (0 - 3 months),... etcetera
      .

      You’ve discovered a small bug... Which is easily fixed. Open up eform.in.php in the assets/snippets/eform folder and look for this bit of code (approximately around line 800.

      //<?php
      //add valid values to formats... (extension to $formats)
      if($formats[$name] && !$formats[$name][5])
         $formats[$name][4] = $_lang['ef_failed_default'];
         //convert commas in values to something else !
         $formats[$name][5]= "#LIST " . implode(",",str_replace(',',',',$validValues));
      break;
      //?>
      
      

      The { } brackets are missing for the if statement, so all you have to do is replace this with:

      //<?php
      //add valid values to formats... (extension to $formats)
      if($formats[$name] && !$formats[$name][5]){
         $formats[$name][4] = $_lang['ef_failed_default'];
         //convert commas in values to something else !
         $formats[$name][5]= "#LIST " . implode(",",str_replace(',',',',$validValues));
      }
      break;
      
      //?>
      
        • 6725
        • 12 Posts
        Thanks for the tip Toby smiley I’ve found the missing brackets (or rather not found them) and put them in.

        I haven’t had time to test it yet though, but I’ll let you know how it goes once I do.

        David
          • 6725
          • 12 Posts
          Just to let you know I have now tested this and it is working as expected after adding the {} brackets to the if statement. Can’t wait to use this powerful feature smiley

          Thanks again for your help!

          David