I dont understand the problem im facing.

I'm building a big form (in which you can add products, modify quantity, etc etc and validate.

I'm getting consistency data problem between what's in $form_state['values'] and what's in $form_state['input']

$form_state['values'] are never up-to-date ...

if I change a quantity field value, and then validate the ofrm, I will find the right quantity in $form_state['input'] but not in $form_state['values'].

Say it passes the validation step, if I submit a second time the form, then I will have the correct values in $form_state['values'].

Another example : The validation fails if a quantitu is set to 0. When the form display itself after the failure, all quantity fields are reset to the value they were after the previous form loading (Am I clear enough ?)

I dont understand what could make this happen ...

Found this post : When are '$form_state['values'] copied to '$form' on rebuild?

Petroll commented it :

When you submit a form with user input, the input gets stored in $form_state['input'] and later (after validation) in $form_state['values']. But when you, then, rebuild the form, the values are (and AFAIK have to be) are ?somehow? given as parameters to element process functions (that create the FAPI arrays of elements).

That make sense... If validation fails, $form_state['values'] is not updated with $form_state['input']. So the form is rebuild with the old values.

But What I dont understand is why all the values are reseted ...

Lets say Ive 5 products. If I modify each quantity, and I set one of them to 0, the validation will fail and all my inputs will be lost.

  • in which step are you accesssing that values? Validation? Build step? Process phase? Form alter step? Adding your code might help.
    – sanzante
    Commented Feb 3, 2015 at 10:35
  • some examples : When the validation process fails, old values are used as default values in all inputs.
    – Math666
    Commented Feb 3, 2015 at 10:40
  • Are you taking the $form_state as reference? Commented Feb 3, 2015 at 10:40
  • I will try to add code but wont do it before tomorrow I think. Meanwhile ill add others examples
    – Math666
    Commented Feb 3, 2015 at 10:40
  • yes form_state is used by reference everywhere (validation, submit, other functions)
    – Math666
    Commented Feb 3, 2015 at 10:42

1 Answer 1


Did find a solution : #after_build attribute added to my textfield.

Then added a new function to check if the form_state['input']['mytextfield'] is set. If so, using it to change the #value of the element.

important : altering #default_value in the after_build function didn't work, had to change the #value


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.