Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 鉴于帖子的结果,如何更改值并重新提交?_Php_Html - Fatal编程技术网

Php 鉴于帖子的结果,如何更改值并重新提交?

Php 鉴于帖子的结果,如何更改值并重新提交?,php,html,Php,Html,假设我有一个HTML表单,允许您输入姓名和年龄,并返回具有该姓名和年龄的人的列表 <form method="post" action="/search_results"> <input type="text" name="personName"> <input type="text" name="personAge"> <input type="submit" value="Submit!"> </form>

假设我有一个HTML表单,允许您输入姓名和年龄,并返回具有该姓名和年龄的人的列表

<form method="post" action="/search_results">
   <input type="text" name="personName">
   <input type="text" name="personAge">
   <input type="submit" value="Submit!">
</form>

在搜索结果页面上,我有一个结果列表,但我一次只显示50个,并且允许用户通过按钮在页面之间前进/后退。因此,结果页面还将查找发布的“pageNumber”值,如果没有,则默认为0

当他们点击一个按钮时,我如何重新提交年龄和姓名,并从按钮中提交相应的页码

我正在使用PHP


<form method="post" action="/search_results">
  <input type="text" name="personName" value="<?php echo (isset($formdata['personName'])?$formdata['psersonName']:"") ?>">
  <input type="text" name="personAge" value="<?php echo (isset($formdata['personAge'])?$formdata['personAge']:"") ?>">
  <input type="hidden" name="currentPage" value="<?php echo (isset($formdata['currentPage'])?$formdata['currentPage']:"0") ?>">
  <input type="submit" value="Submit!">
</form>


将隐藏字段添加到表单:

<form name=search"" method="post" action="/search_results">
  <input type="hidden" name="pageNumber"
    value="<?php echo isset($_POST['pageNumber']) ? (int) $_POST['pageNumber'] : 0; ?>">
   <input type="text" name="personName">
   <input type="text" name="personAge">
   <input type="submit" value="Submit!">
</form>


将隐藏字段添加到表单:

<form name=search"" method="post" action="/search_results">
  <input type="hidden" name="pageNumber"
    value="<?php echo isset($_POST['pageNumber']) ? (int) $_POST['pageNumber'] : 0; ?>">
   <input type="text" name="personName">
   <input type="text" name="personAge">
   <input type="submit" value="Submit!">
</form>


分页的最佳实践是使用包含参数(GET)和非参数(POST)的简单链接。这样,当你在url中有参数时,你可以缓存它,添加到收藏夹,被谷歌索引,在email/facebook中共享你的页面等等

<a href='http://example.com/?personName=<?=$_POST['personName']?>&personAge=<?=$_POST['personAge']?>&page=<?=$next_page_number?>'>Next</a>

如果出于某种原因,您必须或确实想要使用POST,您可以将值保存在页面中表单中的隐藏输入中,然后在单击“下一页”按钮时将其保存

表格示例:

请注意,这只是一个示例,您应该清理变量,而不是直接从$\u POST中放置它们

<form name="pagination" method="post" action="/search_results">
    <input type="hidden" name="page" id="page" value="2">
    <input type="hidden" name="personName" value='<?=$_POST['personName'];?>'>
    <input type="hidden" name="personAge" value='<?=$_POST['personAge'];?>'>
</form>


分页的最佳实践是使用包含参数(GET)和非参数(POST)的简单链接。这样,当你在url中有参数时,你可以缓存它,添加到收藏夹,被谷歌索引,在email/facebook中共享你的页面等等

<a href='http://example.com/?personName=<?=$_POST['personName']?>&personAge=<?=$_POST['personAge']?>&page=<?=$next_page_number?>'>Next</a>

如果出于某种原因,您必须或确实想要使用POST,您可以将值保存在页面中表单中的隐藏输入中,然后在单击“下一页”按钮时将其保存

表格示例:

请注意,这只是一个示例,您应该清理变量,而不是直接从$\u POST中放置它们

<form name="pagination" method="post" action="/search_results">
    <input type="hidden" name="page" id="page" value="2">
    <input type="hidden" name="personName" value='<?=$_POST['personName'];?>'>
    <input type="hidden" name="personAge" value='<?=$_POST['personAge'];?>'>
</form>

<a href='http://example.com/?personName=<?=$_POST['personName']?>&personAge=<?=$_POST['personAge']?>&page=<?=$next_page_number?>'>Next</a>
<form name="pagination" method="post" action="/search_results">
    <input type="hidden" name="page" id="page" value="2">
    <input type="hidden" name="personName" value='<?=$_POST['personName'];?>'>
    <input type="hidden" name="personAge" value='<?=$_POST['personAge'];?>'>
</form>
<button onclick='document.getElementById("page").value= "2";document.pagination.submit();'>Next page</button>