You are here

function nodereference_optionwidgets_validate in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 modules/nodereference/nodereference.module \nodereference_optionwidgets_validate()

Validate a select/buttons element.

Remove the wrapper layer and set the right element's value. We don't know exactly where this element is, so we drill down through the element until we get to our key.

We use $form_state['values'] instead of $element['#value'] to be sure we have the most accurate value when other modules like optionwidgets are using #element_validate to alter the value.

2 string references to 'nodereference_optionwidgets_validate'
nodereference_buttons_process in modules/nodereference/nodereference.module
Process an individual element.
nodereference_select_process in modules/nodereference/nodereference.module
Process an individual element.

File

modules/nodereference/nodereference.module, line 703
Defines a field type for referencing one node from another.

Code

function nodereference_optionwidgets_validate($element, &$form_state) {
  $field_key = $element['#columns'][0];
  $value = $form_state['values'];
  $new_parents = array();
  foreach ($element['#parents'] as $parent) {
    $value = $value[$parent];

    // Use === to be sure we get right results if parent is a zero (delta) value.
    if ($parent === $field_key) {
      $element['#parents'] = $new_parents;
      form_set_value($element, $value, $form_state);
      break;
    }
    $new_parents[] = $parent;
  }
}