views:

26

answers:

1

In my hook form alter, this is the date of birth array:

[Birthdate] => Array(
  [#type] => fieldset
  [#title] => Birthdate
  [#weight] => 1
  [profile_birthdate] => Array(
    [#type] => date
    [#title] => Birthdate
    [#default_value] =>
    [#description] => The content of this field is kept private and will not be shown publicly.
    [#required] => 1
  )
)

I have tried:

unset($form['Birthdate']['profile_birthdate']);
     unset($form['Birthdate']);

and that does not work as I still get the "Please enter a valid date of birth" message. I want the field hidden and no message.

+2  A: 

The phrasing of the error message ('... a valid date...') hints on this being issued from a form validation function. Depending on how that is written, it might still try to validate the field, even if you removed it successfully from the form.

If that is the case, you'll need to either override the validation function with a custom version that does not expect the birthdate field (check the content of $form['#validate'] in your hook_form_alter() implementation). Alternatively, instead of removing the field, you could turn it into '#type' => 'hidden' or '#type' => 'value', and provide a default value that passes validation, but then you'll end up assigning bogus birth dates, which might not be what you want.

Henrik Opel
thank you. that did it.
jini

related questions