I have a form which send an ajax request to my server. The form is:
function dokimi_add_to_list_form($form, $form_state) {
$form = array();
$options=array(
'option1'=>'option1',
'option2'=>'option2'
);
$form['private_list'] = array(
'#type' => 'radios',
'#title' => 'Private lists',
'#options' => $options,
'#prefix'=>'<div id="list_list">',
'#suffix'=>'</div>'
);
$form['add_new']= array(
'#type' => 'fieldset',
'#markup' => 'Add a list'
);
$form['add_new']['new_list']= array(
'#type' => 'textfield',
'#title'=> 'New list',
'#default_value' => '',
);
$form['add_new']['add']= array(
'#type' => 'button',
'#value' => t('Add'),
'#ajax'=>array(
'callback' => 'add_to_list_callback',
'wrapper'=>'list_list'
// 'wrapper' is the HTML id of the page element that will be replaced.
)
);
return $form;
}
And the callback function is:
function add_to_list_callback($form, $form_state){
$options=array(
'newoption1'=>'newoption1',
'newoption2'=>'newoption2',
'newoption3'=>'newoption3'
);
$form['private_list'] = array(
'#type' => 'radios',
'#title' => 'Private list',
'#options' => $options,
'#prefix'=>'<div id="list_list">',
'#suffix'=>'</div>'
);
$commands = array();
$commands[]=ajax_command_replace('#list_list', render($form['private_list']));
return array(
'#type'=>'ajax',
'#commands'=>$commands
);
}
When the 'Add' button is clicked, a new array of options should be returned, but I get an empty list instead.
The form is rendered in a ctools modal if that is of importance.
Thanks for any help with this - it's driving me barmy.