3

as far as I understand it whenever you submit and rebuild a form (e.g. 'Add another item' on fields with infinite cardinality) something like this happens:

  1. User submits a form with filled values
  2. User input is copied to $form_state
  3. Element validation happens
  4. Form validation happens
  5. drupal_get_form is called (form is being rebuild)
  6. ??? old user input from $form_state is copied to every $element[#value]
  7. Individual elements of the form are created in $element[#process] callbacks
  8. Rebuild form is shown to a user

My question is, when and how is user input from the old form transferred into the new one?

From what I've been able to understand by reading the documentation it must happen somewhere in drupal_build_form before the element #process callback is called. But when exactly that I haven't been able to find.

//I know about this FAPI flowchart if anyone could point me in the right direction on it I'd appreciate it.

2
  • old user input from $form_state is copied to every $element[#value] is it? Never noticed. By the book #value is used only by button, hidden, image_button, submit, token, value. Where exactly you managed to var_dump or kpr your form and see #values set for elements that wasn't set by you? It is not a rhetorical question. First, you are looking for something and I want to know it really happens. Second, knowing when they are for sure set and when they are not will tell us where to look.
    – Mołot
    Commented Jul 29, 2014 at 6:43
  • @Mołot I'm talkind about $element['#value'], not FAPI #element property. And that one has to be and according the flowchart is set in form_builder function right before the 'process callback' (that actually renders the element FAPI array) is called.
    – Petrroll
    Commented Jul 30, 2014 at 21:40

1 Answer 1

4

Nothing like "??? old user input from $form_state is copied to every $element[#value]" happens. Simply $form_state['input'] is kept so that when the form is built the values are filled in based on that.

3
  • 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).
    – Petrroll
    Commented Jul 30, 2014 at 21:46
  • Because $form_state['input'] is kept and then values is computed from them same as normal submit.
    – user49
    Commented Jul 31, 2014 at 1:27
  • Petroll, if When you submit a form with user input, the input gets stored in $form_state['input'] and later (after validation) in $form_state['values'] is true, so why do we use $form_state['values'] in validation function ?
    – Math666
    Commented Feb 4, 2015 at 9:03

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.