We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27023
    • 36 Posts
    I have a cascading/dependent select box in my eform, that basically works using javascript integrated with some PHP script that pulls in values dependant on the first select box. if there is no secondary value then the second select box does not display.

    The form works great and submits the value selected, however once the site was made live i think there may be some browser compatibility issues as the value is not being pulled through on a large majority of the submissions. I added a PHP USER_AGENT script in the report so now the form shows what browser the form was submitted from. Unfortunately this has not cleared up things for me as i user who submits from IE8 sometimes sends the secondary value through and sometimes not.

    What i’m thinking is that i need to make this a required field, however the usual EFORM validations does not come into play as this select box is processed server side and in the page source all you see is the containing DIV. Is there a way i can validate this as a required field?

    I’ll add the code below so you can get an idea:

    PHP CODE (get_list.php)
    <?php
    switch(@$_REQUEST['claimReferral']){
    	case 'Press':
    		$advanced=array('Local Paper', 'Daily Express','Daily Mail','Daily Mirror','Daily Record', 'Daily Star', 'Scottish Sun', 'The Sun');
    		break;
    	case 'TV': 
    		$advanced=array( 'Alibi','Blighty','Bravo 2','Bravo','Challenge','Channel 5','Comedy Central','Crime and Investigation','Dave','Discovery','Discovery Home and Health','Disc Real Time','Disc Turbo','Disc Shed','DMAX','Eden','FX','ITV2','Living','Living2','Sci Fi','Sky1','Sky2','Sky3','Sky News','Sky Sports News','True Entertainment','True Movies','UKTV Food','UKTV Gardens','UKTV Style','Virgin 1','Watch','Wedding Channel','Yesterday');
    		break;
    	case 'Radio':
    		$advanced=array( 'Galaxy','Smooth','Real');
    
    		break;
    
    	default: 
    		$advanced=false;
    }
    if(!$advanced)echo '';
    else echo '<label for="advancedReferral"><em>*</em></label><select name="advancedRefferal"><option>'.join('</option><option>',$advanced).'</select>';
    


    eform template

    <script type="text/javascript">
    			$(document).ready(selectbox_change);
    			function selectbox_change(){
    				$('#claimReferral').change(update_advanced_list);
    			}
    			function update_advanced_list(){
    				var claimReferral=$('#claimReferral').attr('value');
    				$.get('get_list.php?claimReferral='+claimReferral, show_advanced);
    			}
    			function show_advanced(advanced){
    				$('#advanced_list').html(advanced);
    			}
    </script>
    
                  <div class="form-box">
                        <div id="claimFormArea">
    <form method="post" action="[~[*id*]~]" class="yellow clearfix">
        <input type="hidden" name="formid" value="claimmain" />
    
    
    [+validationmessage+]
    <h2 class="formTitle">To start your claim, please fill out this form</h2><br />
                              <fieldset>
    
      <label for="Title">title <em>*</em></label>
      <select name="claimTitle" id="Title">
        <option value="Mr" selected="selected">Mr</option>
        <option value="Mrs">Mrs</option>
        <option value="Miss">Miss</option>
        <option value="Ms">Ms</option>
        <option value="Dr">Dr</option>
      </select><br />
    
      <label for="FullName">Full Name <em>*</em></label>
      <input type="text" class="text" name="claimFullName" id="FullName" maxlength="60" size="40" eform="Your Name::1:Expected at least two words:#REGEX /^\w+\s\w+/i" /><br />
    
        <label for="email">Email Address <em>*</em></label>
        <input type="text" class="text" name="email" size="40" maxlength="40" eform="Email Address:email:1" /><br />
    
        <label for="telephone">Contact Number <em>*</em></label>
        <input type="text" class="text" name="claimContact" size="40" maxlength="40" eform="Contact No:1" /><br />
    
        <label for="claimPreferred">Preferred Contact Time</label>
    <select name="claimPreferred" id="claimPreferred">
      <option value="8:45-12:00" selected="selected">Morning 8:45-12pm</option>
      <option value="12:00-1:00">Lunch 12pm-1pm</option>
      <option value="14:00-17:00">Afternoon 2pm-5pm</option>
      <option value="17:00-19:00">Evening 5pm-7pm (Tues-Thurs only)</option>
    </select><br />
    
        <label for="claimReferral">Referred by <em>*</em></label>
    <select name="claimReferral" id="claimReferral" eform="Select Referrer::1">
      <option value="" selected="selected">--please choose--</option>
      <option value="Press">The Press</option>
      <option value="TV">TV</option>
      <option value="Radio">Radio</option>
      <option value="Magazine">Magazine</option>
      <option value="Internet">Internet</option>
      <option value="Word of Mouth">Word of Mouth</option>
    </select><br />
    
    
    <div id="advanced_list">
    </div>
    
        <label for="comments">Comments</label>
        <textarea class="textarea" cols="32" rows="5" name="claimComments" eform="Enquiry:html:1"></textarea><p style="text-align:right;padding-right: 100px;">required fields <em>*</em></p>
    
        <input class="submit" style="margin-right: 95px;" type="submit" name="sendClaimEmail" id="sendClaimEmail" value="Submit Enquiry " />
    
        <input class="submit" name="reset" type="reset" value="reset" />
    
    </fieldset>
    </form> 
    </div>
    </div>


    Eform call:

    [!getServer!]
    [!eForm? &formid=`claimmain` &to=`[email protected]` &replyto=`email` &autoSenderName=`ME` &automessage=`eClaimformAuto` &tpl=`eClaimform` &from=`[email protected]` &gotoid=`57` &report=`eClaimreport` &eformOnBeforeMailSent=`getServer` &requiredClass=`invalid` &invalidClass=`invalid` &subject=`Claim Enquiry - Preferred Time ((claimPreferred))`!]
      • 27023
      • 36 Posts
      Ok i had to use advanced validation using the &eformOnValidate function

      Here is the snippet that i including in that:

      <?php
      function reqFields(&$fields, &$vMsg, &$rMsg, &$rClass) { //<-- $rClass holds assoc. array of class names for fields (for eForm > 1.4.4)
      	global $modx;
      
      		/* optional. load parameter values for error css classes */
      		$req_class_name = $modx->event->params['requiredClass'];
      		$inv_class_name = $modx->event->params['invalidClass'];
      		/* end optional */
      
      		if ($fields['claimReferral'] == 'TV'){
      			
      			if ($fields['advancedReferral'] == ''){
      				$rMsg['advancedReferral'] = "The selected referrer requires you to select a secondary referral";  //<-- should be the field name or description only
      				$rClass['advancedReferral'] .= $rClass['advancedReferral'] ? ' ' . $req_class_name : $req_class_name; //optional.
      			}
      
      		} else if ($fields['claimReferral'] == 'Press'){
      
      			if ($fields['advancedReferral'] == ''){
      				$rMsg['advancedReferral'] = "The selected referrer requires you to select a secondary referral";  //<-- should be the field name or description only
      				$rClass['advancedReferral'] .= $rClass['advancedReferral'] ? ' ' . $req_class_name : $req_class_name; //optional.
      			}
      			
      		} else if ($fields['claimReferral'] == 'Radio'){
      
      			if ($fields['advancedReferral'] == ''){
      				$rMsg['advancedReferral'] = "secondary referral";  //<-- should be the field name or description only
      				$rClass['advancedReferral'] .= $rClass['advancedReferral'] ? ' ' . $req_class_name : $req_class_name; //optional.
      			}
      
                      }else if ($fields['claimReferral'] == ''){
                              $vMsg['claimReferral'] = "Referrer is required";  //<-- use $vMsg not $rMsg. Add a full error message
      		        $rClass['claimReferral'] .= $rClass['claimReferral'] ? ' ' . $inv_class_name : $inv_class_name; //optional.
                              }
      
      		
      
      	return true;
      }
      ?>