function webform_component_edit_form_validate in Webform 6.2
Same name and namespace in other branches
- 5.2 webform_components.inc \webform_component_edit_form_validate()
- 6.3 includes/webform.components.inc \webform_component_edit_form_validate()
- 7.4 includes/webform.components.inc \webform_component_edit_form_validate()
- 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 411 - Webform module components handling.
Code
function webform_component_edit_form_validate($form, &$form_state) {
$node = node_load($form_state['values']['nid']);
if (!preg_match('!^[a-z0-9_]+$!', $form_state['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_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 field key %field_key is already in use by the field labeled %existing_field. Please use a unique key.', array(
'%field_key' => $form_state['values']['form_key'],
'%existing_field' => $component['name'],
)));
}
}
// Let the field do any additional validation.
webform_load_components($form_state['values']['type']);
$validate_function = '_webform_edit_validate_' . $form_state['values']['type'];
if (function_exists($validate_function)) {
$validate_function($form, $form_state);
}
}