function _webform_edit_validate_mapping in Webform Bonus Pack 6.3
Same name and namespace in other branches
- 7.3 components/mapping.inc \_webform_edit_validate_mapping()
Element validation callback. Ensure keys are not duplicated.
1 string reference to '_webform_edit_validate_mapping'
- _webform_edit_mapping in components/
mapping.inc - Implementation of _webform_edit_component().
File
- components/
mapping.inc, line 86 - Webform module mapping component.
Code
function _webform_edit_validate_mapping($element, &$form_state) {
// Check for duplicate key values to prevent unexpected data loss. Require
// all options to include a safe_key.
if (!empty($element['#value'])) {
$lines = explode("\n", trim($element['#value']));
$missing_keys = array();
$long_keys = array();
$group = '';
foreach ($lines as $line) {
$matches = array();
$line = trim($line);
if (preg_match('/^\\<([^>]*)\\>$/', $line, $matches)) {
$group = $matches[1];
$key = NULL;
// No need to store group names.
}
elseif (preg_match('/^([^|]*)\\|(.*)$/', $line, $matches)) {
$key = $matches[1];
if (strlen($key) > 128) {
$long_keys[] = $key;
}
}
else {
$missing_keys[] = $line;
}
}
if (!empty($missing_keys)) {
form_error($element, t('Every option must have a key specified. Specify each option as "safe_key|Some readable option".'));
}
if (!empty($long_keys)) {
form_error($element, t('Option keys must be less than 128 characters. The following keys exceed this limit:') . theme('item_list', $long_keys));
}
}
return TRUE;
}