2

I'm building a form and I need to include a 'checkboxes' field.

This is my code:

$form['page-options-' . $nid]['mondi-' . $nid] = array(
    '#title' => 'Mondi Azzurra',
    '#description' => 'Seleziona i mondi azzurra di interesse',
    '#type' => 'checkboxes',
    '#options' => $mondi
  );
}

The $form['page-options-' . $nid] field is a simple fieldset.

For some reason if I sobstitute this

'#options' => $mondi

with

'#options' => array_slice($mondi, 0, 15)

limiting the array to 15 elements it works but if I set it 25 stop working again..

Changin field type from checkcboxes to select [with #multiple attribute set to true] the form works.

This is my hook_form_submit()

function adv_sumbission_form_submit($form, &$form_state) {
  dsm($form_state);

  drupal_set_message('The form is submitted');
}

and this is all my hook_form()

function adv_sumbission_form($form, $form_state) {

  $form['pages'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Pagine'),
    '#weight' => 1
  );

  $nodes = node_load_multiple(array(), array('type' => 'pagine_adv'));
    foreach($nodes as $nid => $value){

      $form['pages']['page-' . $nid] = array(
        '#title' => $value->title,
        '#type' => 'checkbox'
      );  

      $form['page-options-' . $nid] = array(
        '#type' => 'fieldset',
        '#states' => array(
        'visible' => array(
           ':input[name="page-' . $nid.'"]' => array('checked' => TRUE)
         ),),
        '#attributes' =>  array('class' => array('page-options'))
      );

      if( isset($value->field_mondi_azzurra[LANGUAGE_NONE]) 
        && count($value->field_mondi_azzurra[LANGUAGE_NONE]) > 1 ) {
      $mondi = array();

      foreach($value->field_mondi_azzurra[LANGUAGE_NONE] as $mondo){
        $term = taxonomy_term_load($mondo['tid']);
        $mondi['term-'.$term->tid] = htmlentities(t($term->name));
      }

      $form['page-options-' . $nid]['mondi-' . $nid] = array(
        '#title' => 'Mondi Azzurra',
        '#description' => 'Seleziona i mondi azzurra di interesse',
        '#type' => 'checkboxes',
        '#options' => array_slice($mondi, 0, 25),
        '#required' => FALSE,
     );
   }
} // end foreach $nodes

$form['submitform'] = array(
  '#type' => 'submit',
  '#value' => t('Invia richiesta'),
  '#weight' => 6
 );


  return $form;
}

I need to know why there is a kind of limit to the checkboxes I can add and how I can debug where the form elaboration stop not serving to my form_submit my form data.

  • 2
    "The form in the page is correctly generated but there is something wrong when Drupal elaborate it." What do you mean by this? – Chapabu Oct 17 '13 at 15:35
  • 1
    What @Chapabu says: "something wrong" and "not working" are curse of IT world. Is it an error with JS console? Unexpected HTML output? No error and expected HTML but expected behaviour != observed? What you expected and what you observed? – Mołot Oct 17 '13 at 15:42
  • @Shyghar Please provide updates by editing, not in comments. Comments may be deleted at any moment and no one will really care. – Mołot Oct 17 '13 at 15:49
  • Is it better now? – Shyghar Oct 17 '13 at 16:24
  • The only difference appears to be in the type of array key, eg, integer in one and string in the other. So, take a look at the logic in your form_submit. You could throw in a $mondi['x-' . $term->tid] = htmlentities(t($term->name)); or something similar and see if that changes things. – Jimajamma Oct 17 '13 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.