我正在使用PHP和JQuery 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当用户单击submit按钮时,应该显示页面AdminPlatos.php。这是我用来访问page>的代码的一部分
$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我不想去params> rest=1&cat=9
我想这是一个JQuery问题,但我不知道如何避免它。
发布于 2014-06-23 08:32:39
所以这里有完整的代码块..。
$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");,因为您只有一个变量,这应该更清楚。
https://stackoverflow.com/questions/24360646
复制相似问题