$form_alter is not being passed on by reference to .

Comments

xano’s picture

Assigned: doq » Unassigned
Status: Closed (fixed) » Active

$form_state is not being passed on by reference to hook_form_alter().

doq’s picture

Assigned: Unassigned » doq
Status: Active » Fixed

Fixed in dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

xano’s picture

Title: hook_form_alter() doesn't take $form_alter as a reference » hook_form_alter() doesn't take $form_state as a reference
Assigned: Unassigned » doq
Status: Active » Closed (fixed)
steveturnbull-2’s picture

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.

dave reid’s picture

The documentation is being fixed on that to show that it is indeed passed by reference.