Fix for Fix for Fix for Code

  1. <?php
  2. function test_menu() {
  3.   $items['test1'] = array(
  4.     'title'             => 'test1',
  5.     'page callback'     => 'drupal_get_form',
  6.     'page arguments'    => array('test_1_form'),
  7.     'type'              => MENU_NORMAL_ITEM,
  8.     'access callback'   => TRUE,
  9.   );
  10.   $items['test2'] = array(
  11.     'title'             => 'test2',
  12.     'page callback'     => 'drupal_get_form',
  13.     'page arguments'    => array('test_2_form'),
  14.     'type'              => MENU_NORMAL_ITEM,
  15.     'access callback'   => TRUE,
  16.   );
  17.   return $items;
  18. }
  19.  
  20. function test_get_values() {
  21.   $values = array();
  22.   $values[0] = new stdClass;
  23.   $values[0]->uuid = '001';
  24.   $values[0]->name = 'aaa';
  25.   $values[0]->image = theme_image(
  26.     'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png',
  27.     t('No picture available'),
  28.     t("picture"),
  29.     NULL,
  30.     FALSE
  31.   );
  32.   $values[1] = new stdClass;
  33.   $values[1]->uuid = '002';
  34.   $values[1]->name = 'bbb';
  35.   $values[1]->image = theme_image(
  36.     'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png',
  37.     t('No picture available'),
  38.     t("picture"),
  39.     NULL,
  40.     FALSE
  41.   );
  42.   return $values;
  43. }
  44.  
  45. function test_1_form() {
  46.   $values = test_get_values();
  47.   $form = array();
  48.   $form['test1'] = array(
  49.     '#type'   => 'fieldset',
  50.     '#title'  => t('test'),
  51.   );
  52.   $i = 0;
  53.   foreach ($values as $value) {
  54.     ++$i;
  55.     $field_name = 'model_'.$i;
  56.     $form['test1'][$field_name] = array(
  57.       '#type'         => 'fieldset',
  58.       '#title'        => $value->name,
  59.       '#collapsible'  => FALSE,
  60.       '#collapsed'    => FALSE,
  61.     );
  62.     $attributes = ($i == 1) ? array('checked' => 'true') : array();
  63.     $form['test1'][$field_name]['uuid'] = array(
  64.       '#type'       => 'radio',
  65.       '#value'      => $value->uuid,
  66.       '#attributes' => $attributes,
  67.     );
  68.     $form['test1'][$field_name]['picture'] = array(
  69.       '#type'   => 'item',
  70.       '#value'  => $value->image,
  71.     );
  72.   }
  73.   $form['submit'] = array(
  74.     '#type'   => 'submit',
  75.     '#value'  => 'go!!!'
  76.   );
  77.   return $form;
  78. }
  79.  
  80. function test_1_form_submit($form, &$form_state) {
  81.  drupal_set_message('<pre>'.print_r($form_state, true).'</pre>');
  82. }
  83.  
  84. function test_2_form() {
  85.   $values = test_get_values();
  86.   $form = array();
  87.   $form['test2'] = array(
  88.     '#type'   => 'fieldset',
  89.     '#title'  => t('test'),
  90.   );
  91.   $options = array();
  92.   $i = 0;
  93.   foreach ($values as $value) {
  94.     ++$i;
  95.     $field_name = 'model_'.$i;
  96.     $options[$field_name] = array(
  97.       '#type'         => 'fieldset',
  98.       '#title'        => $value->name,
  99.       '#collapsible'  => FALSE,
  100.       '#collapsed'    => FALSE,
  101.     );
  102.     $attributes = ($i == 1) ? array('checked' => 'true') : array();
  103.     $options[$field_name]['uuid'] = array(
  104.       '#type'       => 'radio',
  105.       '#value'      => $value->uuid,
  106.       '#attributes' => $attributes,
  107.     );
  108.     $options[$field_name]['picture'] = array(
  109.       '#type'   => 'item',
  110.       '#value'  => $value->image,
  111.     );
  112.   }
  113.   $form['test2']['models'] = array(
  114.     '#type'     => 'radios',
  115.     '#options'  => $options,
  116.   );
  117.   $form['test'] = array(
  118.     '#type'     => 'radios',
  119.     '#options'  => array(
  120.       'aaa' => 'aaa',
  121.       'bbb' => 'bbb'
  122.     ),
  123.   );
  124.   $form['submit'] = array(
  125.     '#type'   => 'submit',
  126.     '#value'  => 'go!!!'
  127.   );
  128.   return $form;
  129. }
  130.  
  131. function test_2_form_submit($form, &$form_state) {
  132.  drupal_set_message('<pre>'.print_r($form_state, true).'</pre>');
  133. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.