duanlu0559 2014-06-23 07:36
浏览 56
已采纳

表单提交后的URL重定向没有继承的参数

I am working on a web site using PHP and JQuery Mobile. On a page I have a form:

 <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>

The URL from the page is:

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

When the user clicks on the submit button, the page AdminPlatos.php should be shown. This is the part of the code that I am using to go to the page>

$insertGoTo = "AdminPlatos.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

But the launched URL is?

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

And I don't want to get there the params> rest=1&cat=9

I guess this is a JQuery issue, but I don't know how to avoid it.

  • 写回答

1条回答 默认 最新

  • dragon8002 2014-06-23 08:32
    关注

    So, here you have complete block of code...

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

    I used !empty($_POST['cat']), because you are going to use just 'cat' and !empty() better fit than isset(), because 'cat' could be empty, but isset() would wtill return true;

    Then I used header("Location: $insertGoTo");, because you have single one variable and this should be more clear to read.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行