By flebas on
Hello,
I am writing a module and I want to update the form content during user input.
I want to update a textfield when the user click on a button.
I process button input in hook_nodeapi, but I cannot get the form updated.
I use form_set_value, there are no error and values are changed in the debugger, but the displayed form remains unchanged. What am I missing ?
function bs_document_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch($op) {
case 'validate':
// detect button
if ($a3['#post']['op'] == BS_GALERIE_SELECT) {
if (($gal = intval($a3['#post']['galerie_select'])) > 0) {
$exposition = bs_galerie_adresse($gal);
form_set_value($a3['grp_entete']['exposition'], $exposition);
}
}
break;
Comments
jQuery?
Maybe a jQuery or javascript function would be required if it is during user input.
http://www.rimian.com.au
...
Form values are actually stored in two different places: in a global $form_values array, and in the '#value' slot of each element. When you use form_set_values() you affect only the $form_values array. But when the form is shown --when there's $_POST data-- it is the '#value' slots that are used.
When you use
How can I change the value of '#value' slot so the change is applied in the next form display ?
I have tried to change it in hook_nodeapi (and changed $a3 to &$a3), but it does not work.
...
There are several ways to do this. I don't know what exactly your scenario is. One way is to add a #after_build handler to the form:
and in it:
It works ! The #after_build
It works !
The #after_build should be added in hook_form_alter, if set in hook_form, it is overwritten during form build.
Thank you very much !
I could not imagine this was not possible with Drupal and did not find any way to do this.