I ran into this on accident and I'm not sure how to prevent this. Basically, I've got a couple of hidden fields on an input form and whenever the validate function fails, the fields that were previously hidden are shown. I've tried adding

['field']['0']['value']['#type'] = "hidden"

to the validation function but that doesn't work as it does in form_alter.

Is this a bug or am I just doing something stupid?

Thanks!

Comments

wim leers’s picture

Assigned: Unassigned » wim leers
Category: bug » support
Status: Active » Fixed

I'm afraid you're doing something stupid. The validation function can't simply change the form:
function yourmodule_formname_validate($form_id, $form_values).

You can't alter your form in the validation stage, it's as simple as that. You *can* set values though (form_set_value()) and set errors (form_set_error()/form_error()).

bishopbooyah’s picture

Hi Wim,

But why is the form hidden attribute being changed during the validation function?

Thanks!

bishopbooyah’s picture

Status: Fixed » Postponed (maintainer needs more info)
wim leers’s picture

Status: Postponed (maintainer needs more info) » Fixed

That must be a flaw in your code. If you debug your code step-by-step, I'm sure you'll find it ;)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.