I’m in the process of converting an existing site to Modx and have run into a problem. I have a form which contains an option list containing a number of indexed place names. The form passes the index to a database table.
'></label><select name='parish' eform_options='parish::1' /><option value=1>Ash Priors</option><option value=2>Ashbrittle</option><option value=3>Ashill</option><option value=5>Bathealton</option><option value=6>Beer Crockham</option><option value=7>Bickenhall</option><option value=9>Bishops Hull</option><option value=10>Bishops Lydeard</option><option value=1819>Carlingcott</option><option value=12>Broadway</option><option value=13>Brompton Ralph</option><option value=14>Brompton Regis</option><option value=15>Broomfield</option><option value=16>Brushford</option>
There is no problem with the display of these names on the form itself nor the passing of the index to the database, however I would like to return the associated name in a message to the web site administrator.
J0801170920
An application to act as OPC for the parish of (1) 1 has been received from Bill Johns on 17-Jan-2008 09:20:07. ...
(1) 1 is where the place name should appear in this example it is the index value
If I change the form to pass the place name rather than the index I have a problem with places with more than one word. For example “Ash Priors” appears correctly in the form but is returned as “Ash”.
If I keep the index rather than place name (preferred method) and attempt to use a function called with &eformOnBeforeMailSent to search the main table locate the index and return the associated name I get an error
Fatal error: Call to a member function on a non-object in /public_html/modx/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 14
The function based on the eForm events example works using lines 1-10 so there is no problem with the basic function call.
The function:
<?php
//create job number based on initials and current date/time
function createJobNumber(&$fields){
$jobNum = '';
foreach (explode(' ',$fields['Surname'],3) as $nm)
$jobNum .= strtoupper(substr($nm,0,1));
$jobNum .= date('ymdHi');
//set extra value in fields array
$fields['jobNumber']= $jobNum;
//
$pid =$fields['parish'];
$output = '';
$result= $modx->db->query('SELECT parishes.ParishName FROM parishes WHERE parishes.PKParishId = $pid');
while( $row = $modx->db->getRow( $result ) )
{
// $output .= $row['ParishName']."<br/>";
$output .= $pid; // $row['ParishName'];
$fields['parishname']= $output;
}
//return success
return true;
}
?>
The offending line seems to be:
$result= $modx->db->query('SELECT parishes.ParishName FROM parishes WHERE parishes.PKParishId = $pid');
This line works in a function outside of an eform event call, can anyone see what I’m doing wrong or explain (1) why this won’t work and (2) what is happening when I attempt to use place names instead.
Thanks