function webform_countdown_validate in Webform Countdown 7.2
Same name and namespace in other branches
- 7 webform_countdown.module \webform_countdown_validate()
Validate input against maximum characters.
1 string reference to 'webform_countdown_validate'
- _webform_render_countdown in ./
webform_countdown.module - Implements _webform_render_component().
File
- ./
webform_countdown.module, line 310 - Webform countdown code module.
Code
function webform_countdown_validate($element, $form_state, $form) {
// Check to ensure value has been entered.
if (!empty($element['#value'])) {
if ($element['#webform_component']['extra']['type'] == 'char') {
// Check to ensure character count is less than or equal to max.
// PHP strlen() does not match JavaScripts .length if string has newlines,
// so convert newlines to single char.
$tmpvalue = str_replace("\r\n", "\n", $element['#value']);
if (mb_strlen($tmpvalue) > $element['#webform_component']['extra']['max']) {
form_error($element, t('The @title field should contain a maximum of @max characters.', array(
'@title' => $element['#title'],
'@max' => $element['#webform_component']['extra']['max'],
)));
}
}
else {
if ($element['#webform_component']['extra']['type'] == 'word') {
// Check to ensure word count is less than or equal to max.
if (_webform_countdown_count_words($element['#value']) > $element['#webform_component']['extra']['max']) {
form_error($element, t('The @title field should contain a maximum of @max words.', array(
'@title' => $element['#title'],
'@max' => $element['#webform_component']['extra']['max'],
)));
}
}
}
}
$element['#attached']['js'] = array(
'js' => _webform_countdown_add_counter($element['#webform_component']['form_key'], $element['#webform_component']['extra']['max'], $element['#webform_component']['extra']['type'], $element['#webform_component']['extra']['message']),
);
}