Fixed hidden fields output. Fields are displayed after following table end (if any).
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 25 Mar 2015 14:35:38 +0000 (15:35 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 25 Mar 2015 14:35:38 +0000 (15:35 +0100)
includes/ui/ui_controls.inc
includes/ui/ui_input.inc

index 89decab4d1e928062794204f74ce9afe989e4caa..3d542f12bd9b99f5f99d7ddda641080e28b65194 100644 (file)
@@ -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)."</form>\n";
+       output_hidden();
+       echo "</form>\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 "</table></center>\n";
+       output_hidden();
        if ($breaks)
                br($breaks);
 }
index 9ca13632a5fd7a149e7be85cae1183c981927bba..0d4d0bfebfdebca788e2111a6086e6b7e7eed94a 100644 (file)
@@ -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)
 {