在提交表单后不继承参数的URL重定向


URL redirection after form submitted without inherited params

我正在使用PHPJQuery Mobile的网站上工作。在一个页面上我有一个表单:

 <form method="post" name="form1" id="form1" onsubmit="return comprobardatos()" data-ajax="false" action="<?php echo $editFormAction; ?>">
<p>
  Nombre:
    <input type="text" name="nombre_plato" id="nombre_plato"  value="" size="32" >
<div id="mensajealias"></div><div id="ajaxBusy" style="display: none;"><p><img src="wait.gif"></p></div>
  </p>
<p>Descripción:
  <input type="text" name="descripcion_plato" id="descripción_plato" value=""  size="32"><div id="mensajenombre"></div>
  </p>
<p>Precio 1:
  <input type="text" name="precio1_plato"  value="" onkeypress="if ( isNaN(this.value + String.fromCharCode(event.keyCode) )) return false;" size="32">
  </p>
  <p>Precio 2:
  <input type="text" name="precio2_plato"  value="" onkeypress="if ( isNaN(this.value + String.fromCharCode(event.keyCode) )) return false;" size="32">
  </p>
  <p>Precio 3:
  <input type="text" name="precio3_plato"  value="" onkeypress="if ( isNaN(this.value + String.fromCharCode(event.keyCode) )) return false;" size="32">
  </p>
  <p>Precio 4:
  <input type="text" name="precio4_plato"  value="" onkeypress="if ( isNaN(this.value + String.fromCharCode(event.keyCode) )) return false;" size="32">
  </p>
<p>
  <input type="button" name="clear" data-role="button" data-theme="e" value="Limpiar formulario" onclick="clearForm(this.form);">
  <div id="boton"><input type="submit" data-role="button" data-theme="b"id="insertar" value="Insertar Nuevo Contenido de la Carta" ></div><div id="mensajeboton"></div>
</p>
<p>
          <input type="hidden" name="cadena_plato" value="<?php echo $_SESSION[Region]?>">
          <input type="hidden" name="restaurante_plato" value="<?php echo $_GET['rest']?>">
          <input type="hidden" name="categoria_plato" id="categoria_plato" value="<?php echo $_GET['cat']?>">
                <input type="hidden" name="MM_insert" value="form1">
              </p>
            </form>

来自页面的URL是:

http://.../NuevoAdminPlato.php?rest=1&cat=9

当用户点击提交按钮时,页面adminplato .php应该会显示出来。这是我用来转到>

页面的代码的一部分
$insertGoTo = "AdminPlatos.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

但是启动的URL是?

http://.../AdminPlatos.php?rest=1&cat=9

我不想在这里输入参数> rest=1&cat=9

我猜这是一个JQuery问题,但我不知道如何避免它。

那么,这里你有一个完整的代码块…

$insertGoTo = "AdminPlatos.php";
if(!empty($_POST['cat'])) {
  $insertGoTo .= '?id=something';
  $insertGoTo .= '&cat='.$_POST['cat'];
  header("Location: $insertGoTo");
}

我使用!empty($_POST['cat']),因为你只使用'cat'和!empty()isset()更适合,因为'cat'可以是空的,但isset()将返回true;

然后我使用header("Location: $insertGoTo");,因为你只有一个变量,这应该更清楚地阅读