You are here

function petreference_optionwidgets_validate in Previewable email templates 6

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 'petreference_optionwidgets_validate'
petreference_buttons_process in modules/petreference/petreference.module
Process an individual element.
petreference_select_process in modules/petreference/petreference.module
Process an individual element.

File

modules/petreference/petreference.module, line 633
Defines a field type for referencing pet template to a node.

Code

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