<?php
while ($row = mysql_fetch_assoc($res)) {
$out .= "<option value=\"{$row['pagetitle']}\"";
if ($row['id'] == $_GET['job']) {
$out .= ' selected="selected"';
}
$out .= ">{$row['pagetitle']}</option>\n";
}
?>http://example.com/jobs/apply.html?role=Manager
<option value="">Speculative enquiry</option> <option value="Sales Manager" selected="selected">Sales Manager 23</option>
$templates['tpl']=str_replace('[+display_job_options+]',$out,$templates['tpl']);<select name="position" > <option value="" selected='selected'>Speculative enquiry</option> <option value="Sales Manager" >Sales Manager 23</option> </select>
eForm should honour the selected attribute when parsing your form template. Post your templates, snippet call and code and I’ll have a look to see where it goes wrong.
[!GetJobOptions!] [!eForm? &formid=`JobForm` &tpl=`JobForm` &report=`JobEmail` &eFormOnBeforeFormParse=`eformGetJobOptions` &to=`[email protected]` &sendAsText=`1` &subject=`Job Enquiry`!]
<?php
if( !function_exists('eformGetJobOptions') ) {
function eformGetJobOptions(&$fields,&$templates){
global $modx;
$out = "<option value=\"\">Speculative enquiry</option>\n";
$res = mysql_query("SELECT id,pagetitle FROM modx_site_content WHERE parent='24' AND published='1'");
while ($row = mysql_fetch_assoc($res)) {
$out .= "<option value=\"{$row['pagetitle']}\"";
if ($row['id'] == $_GET['job']) {
$out .= ' selected="selected"';
}
$out .= ">{$row['pagetitle']} {$row['id']}</option>\n";
}
$templates['tpl']=str_replace('[+display_job_options+]',$out,$templates['tpl']);
return true;
}
}
return '';
?><div class="hr"></div>
<script type="text/javascript" src="/js/valid.js"></script>
[+validationmessage+]
<form id="JobForm" action="[~[*id*]~]" method="post" enctype="multipart/form-data">
<table style="margin-left: 20px">
<tr>
<td width="135"><strong>Name</strong></td>
<td><input type="text" name="name" eform="Your Name::1:Expected at least two words:#REGEX /^\w+\s\w+/i" onblur="return 'Name_req'"></td>
</tr>
<tr>
<td>Current job title</td>
<td><input type="text" name="jobtitle"></td>
</tr>
<tr>
<td>Prospective position</td>
<td><select name="position">
[+display_job_options+]
</select></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td><input type="text" name="email" eform="Your Email address:email:1" onblur="return 'Email_req'"></td>
</tr>
<tr>
<td><strong>Phone number</strong></td>
<td><input type="text" name="telephone" eform="Your Phone number::1" onblur="return 'Phone number_req'"></td>
</tr>
<tr>
<td>Covering letter</td>
<td><textarea name="letter" style="height: 100px"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Attach CV</td>
<td><input type="file" name="cv" eform="Attachment:file:0:Only upload of text documents are supported:#LIST pdf,txt,doc,rtf,docx "></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<div class="hr"></div>
<a href="[~6~]" style="float: left">« back to jobs</a>
<input id="submit" type="image" name="submit" src="images/apply-now.png" width="216" height="46" onclick="return Validate(document.forms.TalkToUs)" style="float: right">
</form>