You are here

function userreference_optionwidgets_validate in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 modules/userreference/userreference.module \userreference_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 'userreference_optionwidgets_validate'
userreference_buttons_process in modules/userreference/userreference.module
Process an individual element.
userreference_select_process in modules/userreference/userreference.module
Process an individual element.

File

modules/userreference/userreference.module, line 584
Defines a field type for referencing a user from a node.

Code

function userreference_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;
  }
}