function word_link_add_form_validate in Word Link 7
Same name and namespace in other branches
- 8 word_link.admin.inc \word_link_add_form_validate()
- 7.2 word_link.admin.inc \word_link_add_form_validate()
Validate form for add or edit page.
File
- ./
word_link.admin.inc, line 393 - Administrative pages for the Word Link module.
Code
function word_link_add_form_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Save')) {
$args = arg();
$normal_path = drupal_get_normal_path($form_state['values']['url']);
$arg = empty($args[5]) ? 0 : $args[5];
$exist = word_link_word_exist(trim($form_state['values']['text']), $arg);
$regex_validate = '/^[_a-zA-Z]+[_a-zA-Z0-9-\\s]*$/';
if ($exist) {
form_set_error('text', t('This word already exists.'));
}
if (!drupal_valid_path($normal_path)) {
form_set_error('url', t("The path '@url' is either invalid or you do not have access to it.", array(
'@url' => $form_state['values']['url'],
)));
}
if (!empty($form_state['values']['class']) && !preg_match($regex_validate, trim($form_state['values']['class']))) {
form_set_error('class', t('Class is not valid.'));
}
if (!empty($form_state['values']['rel']) && !preg_match($regex_validate, trim($form_state['values']['rel']))) {
form_set_error('rel', t('Rel is not valid.'));
}
}
}