You are here

function postal_code_field_widget_form in Postal Code 7

Implements hook_field_widget_form().

File

./postal_code.module, line 175

Code

function postal_code_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $matches = array();
  if (preg_match('/^postal_code_([a-z]{2,3})_postal_code_form$/', $instance['widget']['type'], $matches)) {
    $element['postal'] = array(
      '#type' => 'textfield',
      '#title' => filter_xss_admin($instance['label']),
      '#maxlength' => 16,
      '#required' => $element['#required'],
      '#default_value' => isset($items[$delta]['postal']) ? check_plain($items[$delta]['postal']) : NULL,
      '#element_validate' => array(
        '_postal_code_postal_validate',
      ),
      '#description' => filter_xss_admin($instance['description']),
    );
    $element['postal_type'] = array(
      '#type' => 'hidden',
      '#value' => $matches[1],
    );
  }
  return $element;
}