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

    I need a form where the customer can choose values between 0 and 10. The problem: 0 isn’t an integer value and a float like 0.0 is a no no, because the customer will not understand why he had choosen 0.0 single rooms like the copy of the email will state wink

    Please, what can I do?

    Thank you

      • 18830
      • 161 Posts
      Hm, I tried it with some types of validation - without success:

      eform="single room::1"
      
      eform="single room:float:1"
      
      eform="single room:string:1::#REGEX [A-Za-z0-9]"


      What I don’t understand: when I replace the "0" with "none" and leave 1, 2, 3... untouched, the last rule will work.  huh But switching back to "0" will produce an error message  :’(  Removing "String" from the validation rule does not help.

      What I found at the eForm-manual is this hint: "The listbox, checkbox and radio fields do normally not require the datatype to be set. eForm will recognize these automatically. It will validate the values against the list of values placed in the form."

      But why won’t accept it the "0"?
        • 30223
        • 1,010 Posts
        Ah, yes... small bug. Caught out by php’s loose handling of what’s true or false.. the value 0 is evaluated as false in the form parser and therefore not added to the value list.

        You’ll need to make a change in eform.inc.php line 738 (eform 1.4.3).

        In the eFormParseTemplate function change this line:
        //    if($value) $validValues[] = $value;

        to:
        if( trim($value)!='' ) $validValues[] = $value;


        Here it is again in context...

        <?php
        case "select":
          //replace with 'cleaned' tag and added placeholder
          $newTag = buildTagPlaceholder('select',$tagAttributes,$name);
          $tpl = str_replace($fieldTags[$i],$newTag,$tpl);
          if($formats[$name]) $formats[$name][2]='listbox';
        
          //Get the whole select block with option tags
          $regExp = "#<select .*?name=".$tagAttributes['name']."[^>]*?".">(.*?)</select>#si";
          preg_match($regExp,$tpl,$matches);
          $optionTags = $matches[1];
        
          $select = $newSelect = $matches[0];
          //get separate option tags and split them up
          preg_match_all("#(<option [^>]*?".">)#si",$optionTags,$matches); //adjusted so it doesn't mess up syntax coloring
          $validValues = array();
          foreach($matches[1] as $option){
            $attr = attr2array($option);
            $value = substr($attr['value'],1,-1); //strip outer quotes
        //change this line
        //    if($value) $validValues[] = $value;
        //to this
            if( trim($value)!='' ) $validValues[] = $value;
        //--
            $newTag = buildTagPlaceholder('option',$attr,$name);
            $newSelect = str_replace($option,$newTag,$newSelect);
          }
          //replace complete select block
          $tpl = str_replace($select,$newSelect,$tpl);
          //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;
        ?>
        


          • 18830
          • 161 Posts
          Thank you, thank you, TobyL.