function cleantalk_regexp_validation in Anti Spam by CleanTalk 7.5
Same name and namespace in other branches
- 7.4 src/Form/CleantalkSettingsForm.php \cleantalk_regexp_validation()
Validating the URL exclusion string
Parameters
$element:
$form_state:
$form:
Return value
'form_error()' or nothing
1 string reference to 'cleantalk_regexp_validation'
- cleantalk_settings_form in src/
Form/ CleantalkSettingsForm.php - Cleantalk settings form.
File
- src/
Form/ CleantalkSettingsForm.php, line 297 - CleanTalk module admin functions.
Code
function cleantalk_regexp_validation($element, &$form_state, $form) {
if ($form_state['values']['cleantalk_url_exclusions_regexp']) {
$errors = array();
if (!empty($element['#value'])) {
$exclusions = explode(',', $element['#value']);
foreach ($exclusions as $exclusion) {
$sanitized_exclusion = trim($exclusion);
if (!empty($sanitized_exclusion)) {
if (!apbct_is_regexp($sanitized_exclusion)) {
$errors[] = $sanitized_exclusion;
}
}
}
}
if (!empty($errors)) {
// Remove the variable (setting) from BD if is not valid
variable_set('cleantalk_url_exclusions', '');
// And trigger an error
form_error($element, t('URL exclusions is not valid.') . ' <strong>' . implode(', ', $errors) . '<strong>');
}
}
}