Hi,
I have not problem creating a dynamic checkboxes with this code.
add_filter("gform_pre_render", "populate_dropdown_users");
function populate_dropdown_users($form)
{
// recollim usuaris registrats
global $wpdb;
$allAuthorIds = $wpdb->get_col( "SELECT ID FROM {$wpdb->users}" );
$authorsInfo = array();
$items = array();
foreach( $allAuthorIds as $authorId ) {
$authorsInfo[$authorId] = get_userdata($authorId);
if($authorsInfo[$authorId]->user_level==0)
{
$items[] = array("value" => $authorId, "text" => "<img src=\"http://www.gravatar.com/avatar/".md5($authorsInfo[$authorId]->user_email)."?s=30\" class=\"img_avatar\">".$authorsInfo[$authorId]->display_name);
}
}
foreach($form['fields'] as &$field)
{
// buscarem els que tenen cssClass == custom_field_usuaris
if(strpos($field['cssClass'],'custom_field_usuaris')===false)
continue;
$field["choices"] = $items;
}
return $form; // retornem el formulari
}
But when I tried to create a form with this checkboxes and populated dynamically a content, only first element is selected.
Example.
$field_values = array();
$field_values['projProfe'] = "2,3";
gravity_form(2, false, false, $display_inactive=false, $field_values, false);
Only checkboxes with 2 value is checked not, checbox with value 3 is checked. If I do this with a checkbox with no pre_render content work correctly.
Any idea?
thanks.