php - 提交表单方法get时保留$_GET ['p']

标签 php html forms

当我使用 get 方法提交表单时,get from 表单将删除之前的 ?p=page1&title=food。 我的网址看起来像 localhost/test/index.php?p=page1&title=0

<form action="" method="get">
<input type="text" name="q" placeholder="Search" />
<input type="submit" />
</form>

在我提交表单后,它会将 localhost/test/index.php?p=page1&title=0 替换为 localhost/test/index.php?q=example我想用 &

q 添加到现有的 url

最佳答案

尝试使用隐藏字段再次发送值

<form action="" method="get">
<input type="hidden" name="p" value="<?php if(isset($_GET['p'])) echo $_GET['p'];?>" />
<input type="hidden" name="title" value="<?php if(isset($_GET['title'])) echo $_GET['title'];?>" />
<input type="text" name="q" placeholder="Search" />
<input type="submit" />
</form>

关于php - 提交表单方法get时保留$_GET ['p'],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24182948/

相关文章:

PHP MySQL 无效查询 bool(False)

php - 如何使用 Psalm 的 UnusedMethod 功能?

html - 如何为背景图像留出边距?

html - HTML 内联中的 CSS 动画

php - 更改 foreach 循环内的初始数组?

javascript - 提交一些数据使用 GET,一些使用 POST 到同一个页面

html - 带有 Bootstrap 的响应式 Canvas

forms - FOSUserBundle 问题与 Twig 形式的plainPassword

对动态创建的文本框进行 javascript 验证

angularjs - 向 iframe 提交表单数据的 Angular 方式