You are here

function webform_component_edit_form_validate in Webform 5.2

Same name and namespace in other branches
  1. 6.3 includes/webform.components.inc \webform_component_edit_form_validate()
  2. 6.2 webform_components.inc \webform_component_edit_form_validate()
  3. 7.4 includes/webform.components.inc \webform_component_edit_form_validate()
  4. 7.3 includes/webform.components.inc \webform_component_edit_form_validate()

Field name validation for the webform unique key. Must be alphanumeric.

File

./webform_components.inc, line 408
Webform module components handling.

Code

function webform_component_edit_form_validate($form_id, $form_values) {
  $node = node_load($form_values['nid']);
  if (!preg_match('!^[a-z0-9_]+$!', $form_values['form_key'])) {
    form_set_error('form_key', t('The field key %field_key is invalid. Please include only lowercase alphanumeric characters and underscores.', array(
      '%field_key' => $form_values['form_key'],
    )));
  }
  foreach ($node->webform['components'] as $cid => $component) {
    if (($component['cid'] != $form_values['cid'] || $form_values['clone']) && $component['pid'] == $form_values['pid'] && strcasecmp($component['form_key'], $form_values['form_key']) == 0) {
      form_set_error('form_key', t('The field key %field_key is already in use by the field labeled %existing_field. Please use a unique key.', array(
        '%field_key' => $form_values['form_key'],
        '%existing_field' => $component['name'],
      )));
    }
  }

  // Let the field do any additional validation.
  webform_load_components($form_values['type']);
  $validate_function = '_webform_edit_validate_' . $form_values['type'];
  if (function_exists($validate_function)) {
    $validate_function($form_values);
  }
}