Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Output _formvars when closing the renderer,
instead of when opening the form. This way can output all expected form variables for all rendered sub-forms at once.
Fixes bug #14604.
Did I mention that Horde_Form is a mess and desperately needs refactoring?
  • Loading branch information
yunosh committed Apr 3, 2017
1 parent 46a696f commit 506e5c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion framework/Form/lib/Horde/Form.php
Expand Up @@ -416,7 +416,6 @@ function open(&$renderer, &$vars, $action, $method = 'get', $enctype = null)
$enctype = $this->_enctype;
}
$renderer->open($action, $method, $this->_name, $enctype);
$renderer->listFormVars($this);

if (!empty($this->_name)) {
$this->_preserveVarByPost('formname', $this->_name);
Expand Down
20 changes: 19 additions & 1 deletion framework/Form/lib/Horde/Form/Renderer.php
Expand Up @@ -32,6 +32,7 @@ class Horde_Form_Renderer {
var $_varRenderer = null;
var $_firstField = null;
var $_stripedRows = false;
var $_forms = array();

/**
* Does the title of the form contain HTML? If so, you are responsible for
Expand Down Expand Up @@ -195,6 +196,7 @@ function end()

function close($focus = true)
{
$this->_listAllFormVars();
echo "</form>\n";
if ($focus) {
$GLOBALS['injector']
Expand All @@ -206,7 +208,7 @@ function close($focus = true)
}
}

function listFormVars(&$form)
function getFormVars($form)
{
$variables = $form->getVariables(true, true);
$vars = array();
Expand Down Expand Up @@ -237,6 +239,20 @@ function listFormVars(&$form)
}
}
}
return $vars;
}

function listFormVars(&$form)
{
echo '<input type="hidden" name="_formvars" value="' . htmlspecialchars(json_encode($this->getFormVars($form))) . '" />';
}

function _listAllFormVars()
{
$vars = array();
foreach ($this->_forms as $form) {
$vars = array_merge($vars, $this->getFormVars($form));
}
echo '<input type="hidden" name="_formvars" value="' . htmlspecialchars(json_encode($vars)) . '" />';
}

Expand All @@ -252,6 +268,8 @@ function renderFormInactive(&$form, &$vars)

function _renderForm(&$form, &$vars, $active)
{
$this->_forms[] = $form;

/* If help is present 3 columns are needed. */
$this->_cols = $form->hasHelp() ? 3 : 2;

Expand Down
4 changes: 2 additions & 2 deletions framework/Form/package.xml
Expand Up @@ -27,7 +27,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Fix regression when submitting multiple forms (Bug #14604).
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -1004,7 +1004,7 @@ Converted to package.xml 2.0 for pear.horde.org
<date>2017-03-20</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Fix regression when submitting multiple forms (Bug #14604).
</notes>
</release>
</changelog>
Expand Down

0 comments on commit 506e5c3

Please sign in to comment.