Im Kontaktformular keine URLs zulassen
am 01.04.2010 - 14:34 Uhr in
Ich will das Kontaktformular so erweitern, dass man damit keine URLs, also Internetadressen, die mit http:// oder www beginnen, versenden kann.
Weiters dürfen auch keine Strings der Form "[url=", "[link=", "<a href" usw vorkommen, also soll das selbst erweitert werden können.
Bitte keine Antworten zum Thema Captcha, darum geht es HIER NICHT!
Es geht exakt darum, was oben zu lesen ist.
Wie kann man über eine Funktion, programmiert in template.tpl.php, etc. diese Dinge abfangen und dabei eine große, gut lesbare Fehlermeldung "Es sind keine Internetadressen, URLs, erlaubt im Kontaktfomular" ausgeben?
Vielen Dank.
- Anmelden oder Registrieren um Kommentare zu schreiben

Also ich weiss, dass es in
am 01.04.2010 - 23:47 Uhr
Also ich weiss, dass es in der Formular-Api eine Eigenschaft #required gibt.
Diese steht normalerweise auf FALSE . Wenn der Wert auf TRUE gesetzt wird, (z.B. durch Eingabe von www. oder href oder ähnliches)
kannst du z.B. deklarieren, dass eine Fehlermeldung erscheint.
Quasi wie ein Zugangscode, nur in die andere Richtung.
Musst du einfach mal nach googeln, mehr weiss ich davon leider auch noch nicht.
Gruß Mike
Hab dir mal noch nen anderen
am 02.04.2010 - 10:09 Uhr
Hab dir mal noch nen anderen Beispielcode rausgesucht, wie man so was noch lösen kann.
<?php
// $Id$
/**
* @file
* Play with the Form API.
*/
/**
* Implementation of hook_menu().
*/
function formexample_menu() {
$items['formexample'] = array(
'title' => 'View the form',
'page callback' => 'formexample_page',
'access arguments' => array('access content'),
);
return $items;
}
/**
* Menu callback.
* Called when user goes to http://example.com/?q=formexample
*/
function formexample_page() {
$output = t('This page contains our example form.');
// Return the HTML generated from the $form data structure.
$output .= drupal_get_form('formexample_nameform');
return $output;
}
/**
* Define a form.
*/
function formexample_nameform($form_id, $form_state = NULL) {
$form_state['formexample']['spam_score'] = 90;
$form['user_name'] = array(
'#title' => t('Your Name'),
'#type' => 'textfield',
'#description' => t('Please enter your name.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
if (isset($form_state['formexample']['spam_score'])) {
$form['captcha'] = module_invoke_all('captcha', 'generate', 'Math');
}
return $form;
}
/**
* Validate the form.
*/
function formexample_nameform_validate($form_id, &$form_state) {
if ($form_state['values']['user_name'] == 'King Kong') {
// We notify the form API that this field has failed validation.
form_set_error('user_name',
t('King Kong is not allowed to use this form.'));
}
}
/**
* Handle post-validation form submission.
*/
function formexample_nameform_submit($form_id, $form_state) {
$name = $form_state['values']['user_name'];
drupal_set_message(t('Thanks for filling out the form, %name',
array('%name' => $name)));
}
function formexample_nameform_validate($form_id, &$form_state) {if ($form_state['values']['user_name'] == 'King Kong') {
// We notify the form API that this field has failed validation.
form_set_error('user_name',
t('King Kong is not allowed to use this form.'));
}
}
Grüße Mike