You are here

function webform_component_edit_form_validate in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform_components.inc \webform_component_edit_form_validate()
  2. 6.3 includes/webform.components.inc \webform_component_edit_form_validate()
  3. 6.2 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

includes/webform.components.inc, line 637
Webform module component handling.

Code

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