You are here

function cck_select_other_process in CCK Select Other 6

Same name and namespace in other branches
  1. 7 cck_select_other.module \cck_select_other_process()

Process an individual element.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.

The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'cck_select_other_process'
cck_select_other_elements in ./cck_select_other.module
Implementation of hook_elements

File

./cck_select_other.module, line 128
Implements a select list widget that lets a user provide an alternate option.

Code

function cck_select_other_process($element, $edit, &$form_state, $form) {
  $field_name = $element['#field_name'];
  $field = $form['#field_info'][$field_name];
  $delta = $element['#delta'];
  $field_key = $element['#columns'][0];
  $element['#type'] = 'fieldset';
  unset($element['#value']);

  //FIXME: still necessary? See new else block down below...
  $element['#collapsible'] = TRUE;
  $element['#collapsed'] = FALSE;
  if ($edit['select_other_list'] == 'other' && !empty($edit['select_other_text_input']) && !empty($edit)) {
    $element['#value'] = array(
      array(
        'value' => $edit['select_other_text_input'],
      ),
    );
    $form_state['values'][$field_name] = $element['#value'][$delta];
    $form_state['clicked_button']['#post'][$field_name] = $element['#value'][$delta];
  }
  elseif (!empty($edit)) {
    $element['#value'] = array(
      array(
        'value' => $edit['select_other_list'],
      ),
    );
    $form_state['values'][$field_name] = $element['#value'][$delta];
    $form_state['clicked_button']['#post'][$field_name] = $element['#value'][$delta];
  }
  else {
    $element['#value'] = '';
  }
  if (empty($element['#element_validate'])) {
    $element['#element_validate'] = array();
  }
  $form_state['#field_info'][$field['field_name']] = $field;
  if (!empty($edit)) {
    unset($element['select_other_list']);
    unset($element['select_other_text_input']);
  }
  return $element;
}