Hi, I’m trying to pre-populate a checkbox from a database . My form template (badgesFormTpl) contains:
<div>
<label for="badge">Badge?</label>
<input type="radio" name="badge[]" value="yes" eform="badge:1" />Yes
<input type="radio" name="badge[]" value="no" />No
</div>
eForm call is like this:
[!loadFormValuesFromDb!]
[!eForm? &formid=`badgesForm` &noemail=`true` &tpl=`badgesFormTpl` &protectSubmit=`0` &invalidClass=`formerror` &eFormOnBeforeFormParse=`loadFormValues` !]
and my snippet for the eFormOnBeforeFormParse event is:
function loadFormValues( &$fields, &$templates ) {
global $modx;
// get data from db record and add to form fields
$select = $modx->db->select( '*', 'badge_table', 'id = 1' );
$row = $modx->db->getRow( $select );
if ( !empty( $row ))
{
// I THINK THIS IS WHERE THE PROBLEM IS....
$fields['badge'] = $row['badge']
}
}
else
{
// The form has beed posted, let's not disturb the data.
}
return true; // A value of false will stop the eForm parser
}
I know I’m doing something wrong in the event snippet, because I don’t know how to add a value (presumably to $fields array) to output the
checked="checked" code for the relevant radio button
Anyone know how to do this? Thanks