[development] form_set_value and multistep
drupal at dave-cohen.com
Wed Aug 20 22:09:26 UTC 2008
I've written a form element for drupal 5.x which, in it's #validate callback,
converts a comma-seperated string into an array of ids. It uses the
form_set_value() function to change the string value to an array.
My element fails in multistep forms. The reason being that first the form is
processed, then the $form_values which my call to form_set_value() affected
is discarded (at the end of drupal_process_form()) then
drupal_retrieve_form() is called again, this time passing in $_POST (this
happens in drupal_get_form()). Because my call to form_set_value() affects
$form_values and not $_POST, my changes are lost.
I've noticed that if I also change the $_POST after I call form_set_value(), I
can work around the problem:
// Here's the call usually make:
// Here's the workaround that modifies $_POST:
_form_set_value($_POST, $element, $element['#parents'], $items);
For a number of reasons, I feel that call to _form_set_value() is hacky and
does not belong in my code. However, it might be a reasonable addition to
form_set_value(). If I were to submit that as a patch, any chance it would
I'm not the only one who's had problems with form_set_value(). Most people
find workarounds usually avoiding it entirely, but I have yet to find one for
my case. For example, http://drupal.org/node/264743.
More information about the development