Hi,
I am kind of mystified as to how to use form_set_value in Drupal 7.
i.e.
form_set_value($element, $value, &$form_state)
Here is what I don't understand and most examples seem to be silent on the matter..
* where can you use this function? can you use it in a custom function in a module? If so how will it access &$form_state since that is a required parameter? Is &$form_state in scope in a custom function? Is it supposed to be called from a specific function like hook_form_alter? If so how do you set the value at a time of your choosing?
* how do you specify the parameter $element? Some examples mention using #parents to identify where in the $form_values structure you want to put the value... I have seen examples such as $element['#parents'] = array(<<name of form item>>) ;
but I'm not sure of the exact format and if that's right (?)
Any help is much appreciated as there seems to be very little in the way of complete examples for this function for D7...
cheers,
Rowan
Comments
usually one invoke the
usually one invoke the function in a form submit function, where the &$form_state is passed on from the form function itself.
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
skype id : duckzland
Thanks
In the form submit function I can retrieve the hidden form value but that value needs to be updated by other functions - functions that occur at times other than the form submit and after when the form is first rendered. How do you set a value in a form in this situation? There dont seem to be many actual examples or can it simply not be done?
functions that occur at times
you can store the variable for processing at later time in the function that build the form by storing it using $form_state['storage']
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
skype id : duckzland
But how do you set it?
I am able to get the value using that syntax but the issue is how do I set it when im not creating the form or within a form submit function? Ive seen possibilities like form_set_value but that also seems to require being inside a form submit function where you are in scope for %form_state...
I'm not sure you can do that
I'm not sure you can do that outside the form, it is like a security protection, if you change the value of a form, you'll need to rebuild the form, otherwise it will throw validation error.
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
skype id : duckzland
I think I need to change approach
Yes I was starting to come to that conclusion...the other possibilities I thought are maybe either a setting or perhaps just passing variables in the normal PHP way...i'll have to look into it..thanks for your help!!