You are here

function subform_example_subform2 in Subform 7

Form builder; Subform 2.

1 string reference to 'subform_example_subform2'
subform_example_subform1 in ./subform_example.module
Form builder; Subform 1.

File

./subform_example.module, line 197

Code

function subform_example_subform2($form, &$form_state, $title) {
  $form['title'] = array(
    '#type' => 'value',
    '#value' => $title,
  );
  $form['bar'] = array(
    '#type' => 'textfield',
    '#title' => t('Bar (subform 2)'),
  );
  $form['trigger_error'] = array(
    '#type' => 'checkbox',
    '#title' => t('Trigger error (subform 2)'),
  );
  $form['select_id'] = array(
    '#type' => 'value',
    '#value' => isset($form_state['values']['select_id']) ? $form_state['values']['select_id'] : drupal_html_id('ajax_selected_color'),
  );
  $select_id = drupal_html_id('select');
  $form['select'] = array(
    '#type' => 'select',
    '#title' => t('Select (subform 2)'),
    '#options' => array(
      'red' => 'red',
      'green' => 'green',
      'blue' => 'blue',
    ),
    '#ajax' => array(
      'callback' => 'subform_example_simple_form_select_callback',
      'wrapper' => $select_id,
    ),
    '#prefix' => '<div id="' . $select_id . '">',
    '#suffix' => '<div id="' . $form['select_id']['#value'] . '">No color yet selected</div></div>',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit subform 2'),
    '#weight' => 40,
  );
  $form['actions']['validate'] = array(
    '#type' => 'submit',
    '#value' => t('Validate subform 2 - 2nd validator'),
    '#weight' => 40,
    '#submit' => array(
      'subform_example_subform2_validate2',
    ),
  );
  return $form;
}