http://api.drupal.org/api/head/function/form_set_value

Use this function to make changes to form values in the form validate phase, so they will be available in the submit phase in $form_values.

Ok, with you so far...

Specifically, if $form['#parents'] is array('foo', 'bar') and $value is 'baz' then this function will make $form_values['foo']['bar'] to be 'baz'.

Um. What? o_0 #parents? $value? Eh?

We should probably have a source code example, since this is one of our trickier functions for new users to grok.

Comments

mpare’s picture

Category: bug » support

I made a comment over on another node with people, including myself, who have been having some difficulty with this function. Hope this helps. http://drupal.org/node/160160#comment-258277

Peace,
-mpare
www.paretech.com

Did you figure out how to do something? Did you find documentation on Drupal.org inadequate? Well now it's your turn. Document your Success!

ricabrantes’s picture

Version: x.y.z » 5.0
Status: Active » Closed (fixed)

Close, no activity...

webchick’s picture

Version: 5.0 » 7.x-dev
Category: support » bug
Status: Closed (fixed) » Active

Just because there's been no activity doesn't mean this isn't still a bug. ;)

webchick’s picture

Component: forms system » documentation
floretan’s picture

The few places in core where this function gets called are pretty obscure and wouldn't provide new developers with a useful example. A little difference that might make a big impact is renaming the $form parameter to $element to make it clear that we are setting the value of a form element, not the value of the form itself (which wouldn't make much sense).

steven jones’s picture

Assigned: Unassigned » steven jones

I will write something up in a bit...

steven jones’s picture

Category: bug » task
Status: Active » Needs review
StatusFileSize
new2.69 KB

Changed the function's documentation and changed the name of one of the function's parameters to better reflect what it actually is.

floretan’s picture

StatusFileSize
new2.67 KB

This is great. Thank you darthsteven.

I would just rephrase the documentation for the $value parameter (see attached patch), otherwise this looks good.

steven jones’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, lets get this in, then backport.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks! Keep it coming. :)

steven jones’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Reviewed & tested by the community
StatusFileSize
new2.68 KB

Not sure what the procedure is for this, but here's the same documentation for D6.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, I think this is a great addition to Drupal 6, so committed there too.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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