]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/table.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 23 Oct 2017 11:28:01 +0000 (12:28 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 23 Oct 2017 11:28:01 +0000 (12:28 +0100)
lib/php/db/table.php

index 7ea1237bc6b8eaff5d6997e1aad3f04bb94d9a9e..e640aa1b97542bbec8ef11f8b59491bf9305f11e 100644 (file)
@@ -482,13 +482,25 @@ Class Table extends nb {
 
   }
 
-  public static function form_hidden($ignore=[]) {
+  public static function params2hash($keys) {
+      $params = [];
+      foreach ($keys as $k) {
+        $params[$k] = self::p($k);
+        if (!isset($params[$k]) or (string)$params[$k] === '') unset($params[$k]);
+      }
+      return $params;
+  }
+
+  public static function form_hidden($ignore=[],$params=null) {
     $h = '';
+    if (!isset($params)) {
+      $params = self::params2hash(self::$params);
+    }
 
-    foreach (array_diff(self::$params,$ignore) as $p) {
-      if (($v=self::p($p)) or $p=='action') {
-        if (self::p('debug')) $h .= "<label>$p</label>";
-        $h .= '<input type="'.(self::p('debug')?'text':'hidden').'" name="'.$p.'" value="'.$v.'"/>'.NB_EOL;
+    foreach (array_diff($params,$ignore) as $k=>$v) {
+      if (isset($v) or $k=='action') {
+        if (self::p('debug')) $h .= "<label>$k</label>";
+        $h .= '<input type="'.(self::p('debug')?'text':'hidden').'" name="'.$k.'" value="'.$v.'"/>'.NB_EOL;
       }
     }
 
@@ -559,10 +571,14 @@ Class Table extends nb {
 
     if ($this->show_hidden_params and !empty(self::$params)) {
       echo ''
-        .self::form_hidden(['action','referer'])
-      # NB 19.10.17: reactivated for rent 
-        .(!empty($fields['action']) ? '' : '<input type="hidden" name="action" value="'.($add ? 'insert' : 'update').'"/>')
-        .(!empty($_SERVER['HTTP_REFERER']) ? '<input type="hidden" name="referer" value="'.urlencode($_SERVER['HTTP_REFERER']).'" />' : '')
+        .self::form_hidden([],array_merge($this->params2hash(self::$params),[
+          'action' => ($add ? 'insert' : 'update'),
+          'referer' => (!empty($_SERVER['HTTP_REFERER']) ? urlencode($_SERVER['HTTP_REFERER']) : ''),
+        ]))
+# NB 23.10.17         .self::form_hidden(['action','referer'])
+# NB 23.10.17         // NB 19.10.17: action reactivated for rent 
+# NB 23.10.17         .(!empty($fields['action']) ? '' : '<input type="hidden" name="action" value="'.($add ? 'insert' : 'update').'"/>')
+# NB 23.10.17         .(!empty($_SERVER['HTTP_REFERER']) ? '<input type="hidden" name="referer" value="'.urlencode($_SERVER['HTTP_REFERER']).'" />' : '')
       ;
     } else {
       echo (!empty($_SERVER['HTTP_REFERER']) ? '<input type="hidden" name="referer" value="'.urlencode($_SERVER['HTTP_REFERER']).'" />' : '');