From b0de618b47d6ca975589b517217b862189e66780 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Wed, 25 Mar 2015 15:35:38 +0100 Subject: [PATCH] Fixed hidden fields output. Fields are displayed after following table end (if any). --- includes/ui/ui_controls.inc | 14 +++++++++++++- includes/ui/ui_input.inc | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/includes/ui/ui_controls.inc b/includes/ui/ui_controls.inc index 89decab4..3d542f12 100644 --- a/includes/ui/ui_controls.inc +++ b/includes/ui/ui_controls.inc @@ -53,6 +53,16 @@ function start_form($multi=false, $dummy=false, $action="", $name="") } +/* + Flush hidden fields buffer. +*/ +function output_hidden() +{ + global $hidden_fields; + + echo implode('', $hidden_fields); + $hidden_fields = array(); +} //--------------------------------------------------------------------------------- function end_form($breaks=0) @@ -69,7 +79,8 @@ function end_form($breaks=0) hidden('_confirmed'); // helper for final form confirmation hidden('_token', $_SESSION['csrf_token']); - echo implode('', $hidden_fields)."\n"; + output_hidden(); + echo "\n"; $Ajax->activate('_token'); $Ajax->activate('_confirmed'); } @@ -102,6 +113,7 @@ function start_table($class=false, $extra="", $padding='2', $spacing='0') function end_table($breaks=0) { echo "\n"; + output_hidden(); if ($breaks) br($breaks); } diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 9ca13632..0d4d0bfe 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -93,7 +93,12 @@ function input_num($postname=null, $dflt=0) } //--------------------------------------------------------------------------------- -$hidden_fields = array(); // store for hiddn fields attached just before form end (for proper html validation) +// +// Thanks to hidden fields buffering hidden() helper can be used in arbitrary places and +// proper html structure is still preserved. Buffered hidden fields are output on the nearest +// table or form closing tag (see output_hidden()). +// +$hidden_fields = array(); function hidden($name, $value=null, $echo=true) { -- 2.30.2