Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
Actually it does. According to the documentation it's not supposed to - but if you follow the code you'll see that it does pass it by reference. (I'm using D6-13).
Just use ..._form_alter(&$form, &$form_state, $form_id), and you can add stuff to $form_state.
Which was very handy for me because I had a multi-page sub-form to insert into various other forms on the site. The sub-form could have been half-completed in one place then reappear in the same state somewhere else - I needed to be able to set up $form_state['storage'] with the correct starting conditions. Which would have been impossible without this.
Comments
Comment #1
xano$form_state is not being passed on by reference to hook_form_alter().
Comment #2
doq commentedFixed in dev.
Comment #4
xanoComment #5
steveturnbull-2 commentedActually it does. According to the documentation it's not supposed to - but if you follow the code you'll see that it does pass it by reference. (I'm using D6-13).
Just use ..._form_alter(&$form, &$form_state, $form_id), and you can add stuff to $form_state.
Which was very handy for me because I had a multi-page sub-form to insert into various other forms on the site. The sub-form could have been half-completed in one place then reappear in the same state somewhere else - I needed to be able to set up $form_state['storage'] with the correct starting conditions. Which would have been impossible without this.
Comment #6
dave reidThe documentation is being fixed on that to show that it is indeed passed by reference.