By yangke on
In the form validation of a custom module i'm trying to validate a textfield (that should contain a date)
However form_set_error shows no error if i enter a 'wrong' value.
But i can make drupal_set_message show a message
So it's not in the validation logic ..
<?php
/**
* form validate handler for the loe form.
* place all the analysis stuff here.
*/
function loe_validate($form, &$form_state) {
$loe_date = $form_state['values']['loe_date']; // get the date from the text field: format yyyy-mm-dd
$date_array = explode("-", $loe_date); // separate the years, months and days
if (count($date_array) != 3) {form_set_error(t('invalid date'));} // there should be 3 elements in this array
else { // assign the values to variables year, month and day
$year = $date_array[0];
$month = $date_array[1];
$day = $date_array[2];
}
drupal_set_message ('date: '.$day.' '.$month.' '.$year); // show that this is all working
if (checkdate($month,$day,$year) == false) { form_set_error(t('invalid date')) ; drupal_set_message ('invalid');} // show an error!
// do some more validation (irrelevant)
}
?>I have used form_set_error before in a node module where it worked as expected...
What am i doing wrong here?
Comments
SOLVED
the FAPI says to use it like:
form_set_error($name = NULL, $message = '', $reset = FALSE)
however, if you give just one argument it appears to be using it as the name.
doing
<?php form_set_error('name', t('invalid date'));?>works.