Commit 903e9a8b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add sesskey property to pieform hidden element and use it in default form config (bug #771598)



Change-Id: I674f7d900adf952b4c85c221fa679f68ebb3b9cb
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 22c4ba5b
......@@ -1486,8 +1486,9 @@ function pieform_configure() {
'helpcallback' => 'pieform_get_help',
'elements' => array(
'sesskey' => array(
'type' => 'hidden',
'value' => $USER->get('sesskey')
'type' => 'hidden',
'sesskey' => true,
'value' => $USER->get('sesskey')
)
)
);
......
......@@ -35,6 +35,9 @@ function pieform_element_hidden(Pieform $form, $element) {/*{{{*/
if (!array_key_exists('value', $element)) {
throw new PieformException('The hidden element "' . $element['name'] . '" must have a value set');
}
if (!empty($element['sesskey']) && $form->get_property('method') != 'post') {
throw new PieformException('Sesskey values should be POSTed');
}
$value = $form->get_value($element);
if (is_array($value)) {
$result = '';
......@@ -59,9 +62,13 @@ function pieform_element_hidden(Pieform $form, $element) {/*{{{*/
/**
* Returns the value for a hidden element. Hidden elements only listen to the
* 'value' index, and not to GET/POST
* 'value' index, and not to GET/POST, unless the 'sesskey' property is set
* on the element.
*/
function pieform_element_hidden_get_value(Pieform $form, $element) {/*{{{*/
if (!empty($element['sesskey']) && $form->is_submitted()) {
return isset($_POST[$element['name']]) ? $_POST[$element['name']] : null;
}
return $element['value'];
}/*}}}*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment