Forums | Mahara Community

Developers /
Hidden form field values not saving

Stephen C's profile picture
Posts: 117

09 June 2009, 5:04 PM

Any idea why hidden form fields whose values are set via javascript aren't saving?

I have verified that the javascript is indeed setting the field's value correctly.  If I change the field to a text field, it saves fine. Switch it back to a hidden field and it won't save. It's very frustrating.

Nigel's profile picture
Posts: 1643

09 June 2009, 7:09 PM

Hi - yes, this is because the hidden element's definition of get_value (a Pieforms hook) simply returns the element's value, rather than looking in get/post. See lib/pieforms/pieform/elements/hidden.php

This is less than optimal for when people are playing with hidden values via JS - although it does add security in a sense, because you can always trust that the value you put in the pieform definition will be the one returned to you.

I've been meaning to make that behaviour configurable for a while. For now, I think commenting out the entire hook will give you the behaviour you want - as long as you remove the first three lines of pieform_element_hidden as well, and switch to 'defaultvalue' in your pieform definition.

Stephen C's profile picture
Posts: 117

11 June 2009, 6:43 PM

Thanks for the help. I've got it working now.
3 results