We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • In 1.4.2 I am getting validation errors when using the following code for values in forms:

    		<select name="cfBudget" id="cfBudget" eform="Budget::0">
                             <optgroup label="Values are in USD">
    			<option value="n/a">Not applicable</option>
    			<option value="$2500-5000">Small marketing site ($2.5-5K)</option>
    			<option value="$5000-15,000">Intranet/Dashboard ($5-15K)</option>
    			<option value="$15,000-50,000">Med to Lg presence ($15-50K)</option>
    			<option value="$50,000+">Custom Online Service ($50K+)</option>
                            </optgroup>
    		</select></div>


    When I change the values as follows, it works fine:

    		<div><label for="cfBudget">Budget (for jobs):</label>
    		<select name="cfBudget" id="cfBudget" eform="Budget::0">
                             <optgroup label="Values are in USD">
    			<option value="n/a">Not applicable</option>
    			<option value="$2500 to 5000">Small marketing site ($2.5-5K)</option>
    			<option value="$5000 to 15,000">Intranet/Dashboard ($5-15K)</option>
    			<option value="$15,000 to 50,000">Med to Lg presence ($15-50K)</option>
    			<option value="$50,000 and up">Custom Online Service ($50K+)</option>
                            </optgroup>
    		</select></div>


    Perhaps form values need to be run through entity conversion or special chars?
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 30223
      • 1,010 Posts
      The trouble is caused by the comma in the numeric values. eForm automatically sets a #LIST validation rule for select boxes (and radio buttons) and the #LIST expects a comma separated list... Here’s how the validation rule values turn out in your case:

      array (
      0 => ’n/a’,
      1 => ’$2500-5000’,

      2 => ’$5000-15’,
      3 => ’000’,
      4 => ’$15’,
      5 => ’000-50’,
      6 => ’000’,
      7 => ’$50’,
      8 => ’000+’,
      )
      The green values would validate, the rest obviously not. The blue ones are extra values created by wrongly splitting the embedded commmas.

      The solution would be to translate the comma’s when the rule list is generated and translating them back when validating the values...

      2 small hacks in eFrom.inc.php will do the trick:
      <?php
      #LINE 750 - replace
      # $formats[$name][5]= "#LIST " . implode(",",$validValues);
      #with
      $formats[$name][5]= "#LIST " . implode(",",str_replace(',','|~|',$validValues));
      
      #LINE 904 - replace
      # if(!isset($vlist)) explode(',',strtolower(trim($param))); //cached
      #with
      if(!isset($vlist)){ 
          $vlist =  explode(',',strtolower(trim($param))); //cached
          foreach($vlist as $k =>$v) $vlist[$k]=str_replace('|~|',',',$v);
      }
      ?>
      


      I’ll update this (or make an equivalent change) in the next version.