Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By yictory on
i want change price on the fly. but this do not work.
Jquery$('input[name ="pricehidden'"]').val(parseInt($('input[name ="pricehidden'"]').val()) + 100);
HTML
$form['hiddenprice'] = array(
'#type' => 'hidden',
'#value' => 20,
);
i use alert($('input[name="pricehidden"]').val()),it shows the result 120.
but form_state['values']['hiddenprice'] result still 20.
can somebody help me.
Comments
I use $_POST['hiddenprice']
I use $_POST['hiddenprice'] instead $form_state['values']['hiddenprice'],the problem solved.but i still want to know,why $form_state do not work?
-----------------------------
www.linellae.com
+1
Same thing happens to me.
and the solution is..
In the hidden control $form entry, set '#default_value' instead of '#value' :-)
Thanks
#default_value fixed it :)
Just to confirm here, setting
Just to confirm here, setting a hidden field with '#value' means that it cannot be modified on form submission.
If you want to modify the value of the hidden field, you need to use '#default_value', docs link:
https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...
RTFM!
For further support or projects contact me.
Source Control - Web Design, Development and Hosting Oxfordshire, UK
Realize this is old but..
Realize this is old but..
Should mention as well that if you're still noticing a problem after using #default_value, it's likely that you just need to cast the value as a string. Take this for example: