Fix for Fix for Code

  1. <?php
  2.  
  3. function test_menu() {
  4.  
  5.   $items['test1'] = array(
  6.  
  7.     'title'             => 'test1',
  8.  
  9.     'page callback'     => 'drupal_get_form',
  10.  
  11.     'page arguments'    => array('test_1_form'),
  12.  
  13.     'type'              => MENU_NORMAL_ITEM,
  14.  
  15.     'access callback'   => TRUE,
  16.  
  17.   );
  18.  
  19.   $items['test2'] = array(
  20.  
  21.     'title'             => 'test2',
  22.  
  23.     'page callback'     => 'drupal_get_form',
  24.  
  25.     'page arguments'    => array('test_2_form'),
  26.  
  27.     'type'              => MENU_NORMAL_ITEM,
  28.  
  29.     'access callback'   => TRUE,
  30.  
  31.   );
  32.  
  33.   return $items;
  34.  
  35. }
  36.  
  37.  
  38.  
  39. function test_get_values() {
  40.  
  41.   $values = array();
  42.  
  43.   $values[0] = new stdClass;
  44.  
  45.   $values[0]->uuid = '001';
  46.  
  47.   $values[0]->name = 'aaa';
  48.  
  49.   $values[0]->image = theme_image(
  50.  
  51.     'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png',
  52.  
  53.     t('No picture available'),
  54.  
  55.     t("picture"),
  56.  
  57.     NULL,
  58.  
  59.     FALSE
  60.  
  61.   );
  62.  
  63.   $values[1] = new stdClass;
  64.  
  65.   $values[1]->uuid = '002';
  66.  
  67.   $values[1]->name = 'bbb';
  68.  
  69.   $values[1]->image = theme_image(
  70.  
  71.     'http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png',
  72.  
  73.     t('No picture available'),
  74.  
  75.     t("picture"),
  76.  
  77.     NULL,
  78.  
  79.     FALSE
  80.  
  81.   );
  82.  
  83.   return $values;
  84.  
  85. }
  86.  
  87.  
  88.  
  89. function test_1_form() {
  90.  
  91.   $values = test_get_values();
  92.  
  93.   $form = array();
  94.  
  95.   $form['test1'] = array(
  96.  
  97.     '#type'   => 'fieldset',
  98.  
  99.     '#title'  => t('test'),
  100.  
  101.   );
  102.  
  103.   $i = 0;
  104.  
  105.   foreach ($values as $value) {
  106.  
  107.     ++$i;
  108.  
  109.     $field_name = 'model_'.$i;
  110.  
  111.     $form['test1'][$field_name] = array(
  112.  
  113.       '#type'         => 'fieldset',
  114.  
  115.       '#title'        => $value->name,
  116.  
  117.       '#collapsible'  => FALSE,
  118.  
  119.       '#collapsed'    => FALSE,
  120.  
  121.     );
  122.  
  123.     $attributes = ($i == 1) ? array('checked' => 'true') : array();
  124.  
  125.     $form['test1'][$field_name]['uuid'] = array(
  126.  
  127.       '#type'       => 'radio',
  128.  
  129.       '#value'      => $value->uuid,
  130.  
  131.       '#attributes' => $attributes,
  132.  
  133.     );
  134.  
  135.     $form['test1'][$field_name]['picture'] = array(
  136.  
  137.       '#type'   => 'item',
  138.  
  139.       '#value'  => $value->image,
  140.  
  141.     );
  142.  
  143.   }
  144.  
  145.   $form['submit'] = array(
  146.  
  147.     '#type'   => 'submit',
  148.  
  149.     '#value'  => 'go!!!'
  150.  
  151.   );
  152.  
  153.   return $form;
  154.  
  155. }
  156.  
  157.  
  158.  
  159. function test_1_form_submit($form, &$form_state) {
  160.  
  161.  drupal_set_message('<pre>'.print_r($form_state, true).'</pre>');
  162.  
  163. }
  164.  
  165.  
  166.  
  167. function test_2_form() {
  168.  
  169.   $values = test_get_values();
  170.  
  171.   $form = array();
  172.  
  173.   $form['test2'] = array(
  174.  
  175.     '#type'   => 'fieldset',
  176.  
  177.     '#title'  => t('test'),
  178.  
  179.   );
  180.  
  181.   $options = array();
  182.  
  183.   $i = 0;
  184.  
  185.   foreach ($values as $value) {
  186.  
  187.     ++$i;
  188.  
  189.     $field_name = 'model_'.$i;
  190.  
  191.     $options[$field_name] = array(
  192.  
  193.       '#type'         => 'fieldset',
  194.  
  195.       '#title'        => $value->name,
  196.  
  197.       '#collapsible'  => FALSE,
  198.  
  199.       '#collapsed'    => FALSE,
  200.  
  201.     );
  202.  
  203.     $attributes = ($i == 1) ? array('checked' => 'true') : array();
  204.  
  205.     $options[$field_name]['uuid'] = array(
  206.  
  207.       '#type'       => 'radio',
  208.  
  209.       '#value'      => $value->uuid,
  210.  
  211.       '#attributes' => $attributes,
  212.  
  213.     );
  214.  
  215.     $options[$field_name]['picture'] = array(
  216.  
  217.       '#type'   => 'item',
  218.  
  219.       '#value'  => $value->image,
  220.  
  221.     );
  222.  
  223.   }
  224.  
  225.   $form['test2']['models'] = array(
  226.  
  227.     '#type'     => 'radios',
  228.  
  229.     '#options'  => $options,
  230.  
  231.   );
  232.  
  233.   $form['test'] = array(
  234.  
  235.     '#type'     => 'radios',
  236.  
  237.     '#options'  => array(
  238.  
  239.       'aaa' => 'aaa',
  240.  
  241.       'bbb' => 'bbb'
  242.  
  243.     ),
  244.  
  245.   );
  246.  
  247.   $form['submit'] = array(
  248.  
  249.     '#type'   => 'submit',
  250.  
  251.     '#value'  => 'go!!!'
  252.  
  253.   );
  254.  
  255.   return $form;
  256.  
  257. }
  258.  
  259.  
  260.  
  261. function test_2_form_submit($form, &$form_state) {
  262.  
  263.  drupal_set_message('<pre>'.print_r($form_state, true).'</pre>');
  264.  
  265. }

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.