My buildForm() method queries the database and returns data which is used to calculate default values for the form. How can I use these values in submitForm() without querying the database again?

  • Why would you need another query in submit handler? – user21641 Jan 1 '16 at 16:48

Typically, the $form_state object can be used to stash that data. $form_state->getStorage() references a simple array that you can put whatever you like inside, which you can then retrieve in submitForm() the same way.

  • 1
    Specifically, use $form_state->get()/$form_state->set() to set and access these values. – Berdir Jan 1 '16 at 8:11

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.