23

Can someone please tell me the difference between these two variables?

$form_state['values']
$form_state['input']

Optionally some example of action they are used with. I'm wondering especially about using with ajax in drupal form. Which of these should I use in ajax callback to get input values from the form?

26

The crucial difference here is that in most cases you should be using $form_state['values']; since the data on the $form_state['input'] array is raw and unvalidated.

$form_state['input'] is useful for multi-step forms, assuming you are familiar with how to safely handle raw input.... See form_builder for more information...

0

In 99.9% of cases, $form_state['values'] and $form_state['input'] are identical.

But -- beware of a portion of the 1%, particularly when using the date_popup field, as it's input is stored in 'input', but NOT in the 'values' array.

0

$form_state['values'] should be uses in most of the cases as $form_state['input'] hold the raw and invalidated value. Also in $form_state['values'] default values are passed when submission of form fails, but in case of $form_state['input'] NULL is passed.

0

Unless you know what you are doing, you $form_state['values'] it is the processed form values. $form_state['input'] is the raw data. See the code for form_builder: https://api.drupal.org/api....

-4

In the drupal_form_submit function, you can see the following code :

// Populate $form_state['input'] with the submitted values before retrieving
// the form, to be consistent with what drupal_build_form() does for
// non-programmatic submissions (form builder functions may expect it to be
// there).
$form_state['input'] = $form_state['values'];

So it is exactly the same.

  • 4
    Above function is used to programatically submit form... It doesn't answer OP Question.. – Anil Sagar May 6 '14 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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