Hi, ay help appreciated.
The summary of the problem : I have a FormIT form with various fields, some of which are drops downs populated by snippets to connect to MySQL to get the list of entries. I use the FormIT validation process. All is working fine but for one thing : if the user gets some data entry wrong (for example the they enter an invalid email address) such that they get returned to the form, then the data that they had selected in the drop downs on the page is not 'selected' so they have to go through all the selections of drop downs again. How do I retain the selections they made?
So here is what I have:
1. The FormIt call with the validation in (just removed my email address for here)
[[!FormIt? &hooks=saveProperty,email,redirect &emailTo=`
[email protected]` &redirectTo=`36` &validate=`address1:required,address2:required,town:required,telephone:required,contactname:required,contactemail:email:required` &store=`1` &emailTpl=contactTpl]]
2. The list boxes on the page are populated using snippets calls : e.g. below (there are several)
<tr>
<td><br/><span class="error">[[+fi.error.address3]]</span></td>
<td><input id="address3" type="text" name="address3" value="[[+fi.address3]]" size="45" /></td>
<td>Location:</td><td>[[!ddLocations]]</td>
</tr>
3. The snippet looks likes this :
<?php
$reg = $modx->getService('sflocations','SFLocations',$modx->getOption('sponsorfinder.core_path',null,$modx->getOption('core_path').'components/sponsorfinder/').'model/sflocations/',$scriptProperties);
if (!($reg instanceof SFLocations)) return 'Failed to getService for SFLocations';
$sql = 'SELECT id,location FROM modx_sflocations';
$output ='<select id="location"><option>Please select...</option>';
$m = $modx->getManager();
$locations = $modx->getCollection('SFLocation');
if ($locations && count($locations)>0) {
foreach ($locations as $location) {
$locationArray = $location->toArray();
if ( $scriptProperties['location'] == $locationArray['id'] )
$output .= ' selected="yes"';
$output .='<option value="'.stripslashes($locationArray['id']).'">'.stripslashes($locationArray['location']).'</option>';
}
}
$output .='</select>';
return $output;
But the code that should look to insert 'selected = 'yes' against the appropriate selected option appears not be being fired.
Any ideas .... or an alternative solution greatly appreciated.
Cheers for now.