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

index 58bd563cf08937fe7ca289278d63511bbab67f51..5041d0d59b054d62039790b03e0271cb55bc472b 100644 (file)
@@ -534,6 +534,41 @@ Class Table extends nb {
     $st = $this->db()->conn->prepare($sql);
     $st->execute();
 
+    $form_hidden = '';
+    $url_params = [
+      'referer' => (!empty($_SERVER['HTTP_REFERER']) ? urlencode($_SERVER['HTTP_REFERER']) : ''),
+    ];
+    if ($this->show_hidden_params and !empty(self::$params)) {
+      $form_hidden = ''
+        .self::form_hidden([],array_merge($this->params2hash(self::$params),[
+          'action' => ($add ? 'insert' : 'update'),
+          'referer' => (!empty($_SERVER['HTTP_REFERER']) ? urlencode($_SERVER['HTTP_REFERER']) : ''),
+        ]))
+      ;
+
+      foreach (self::$params as $p) {
+        if (!($v = self::p($p))) continue;
+        $url_params[$p] = $v;
+      }
+      $url_params['action'] = ($add ? 'insert' : 'update');
+
+    } else {
+      $form_hidden = (!empty($_SERVER['HTTP_REFERER']) ? '<input type="hidden" name="referer" value="'.urlencode($_SERVER['HTTP_REFERER']).'" />' : '');
+      #echo self::form_hidden(['HTTP_REFERER']);
+    }
+
+    #debug($form_hidden);
+    if (false and $url_params) {
+      $flat = [];
+      foreach ($url_params as $k=>$v) {
+        if ((string)$v === '') continue;
+        $flat[] = $k.'='.urlencode($v);
+      }
+      $form_action .= ( strpos('?',$form_action) === false ? '&amp;' : '' ) . join('&amp;',$flat); 
+      #debug($form_action);
+      $form_hidden = '';
+    }
+
     echo '<form class="db edit form-table" method="post" action="'.$form_action.'">'.NB_EOL;
     echo '<div class="fields">'.NB_EOL;
     $count = 0;
@@ -569,23 +604,7 @@ Class Table extends nb {
       .'</div>'.NB_EOL
     ;
 
-    if ($this->show_hidden_params and !empty(self::$params)) {
-      echo ''
-        .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']).'" />' : '');
-      #echo self::form_hidden(['HTTP_REFERER']);
-    }
-
-    echo '</form>'.NB_EOL;
+    echo $form_hidden.'</form>'.NB_EOL;
 
   }
 
@@ -1614,16 +1633,16 @@ Class Table extends nb {
 
     foreach ($this->fields() as $name => $field) {
 
-      if (!isset($post[$this->key_preff.$name])) {
-        if ($field->key) $this->bye("Missing `$name`!");
-        continue;
-      }
-
       $value = $post[$this->field_preff.$name];
 
       if ($field->key) {
         $keys[] = $name;
 
+        if (!isset($post[$this->key_preff.$name])) {
+          if ($field->key) $this->bye("Missing `$name`!");
+          continue;
+        }
+
         $_value = isset($post[$this->key_preff.$name]) ? $post[$this->key_preff.$name] : null;
 
         if ($_value) {