Forums | Mahara Community

Developers /
Hidden form field values not saving


anonymous profile picture
Account deleted
Posts: 117

09 June 2009, 17:04

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.

anonymous profile picture
Account deleted
Posts: 1643

09 June 2009, 19:09

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.

anonymous profile picture
Account deleted
Posts: 117

11 June 2009, 18:43

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