i have form in drupal which uploads images and has got few checkboxes in it.
Here is the form:
$form['checklist_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Check List'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['checklist_fieldset']['heating'] = array(
'#type' => 'checkboxes',
'#title' => t('Heating options'),
'#options' => array(
'0' => t('Yes'),
'1' => t('No')
),
'#description' => t('Heating details.')
);
and here is my submit function where i am processing image upload and grabbing the checkboxes value as well. I am getting the success message and image is getting uploaded but not getting the value of check boxes.
function property_add_view_submit($form,&$form_state){
$validators = array();
if($file = file_save_upload('p_file1',$validators,file_direcotry_path)){
$heating = array_keys($form_state['values']['heating']);
drupal_set_message(t('Property Saved! '.$heating));
dpm( $form_state['values']['heating']);
}
When you use
#optionson a FAPI element the value passed to the$form_stateis the array key, so you don’t need to usearray_keys().I’m not sure why you’re using
checkboxesfor a yes/no, usually one would use a simplecheckboxelement. However if that’s really what you want to do:#optionscan’t contain on option with0as the array key, it will be automatically filtered out and you’ll never know if that option has been checked.$heating_options_chosen = array_filter($form_state['values']['heating']to get the selected checkbox options.I honestly think your code should look like this though: