通过表单将POST数据传递到同一页面上 [英] Passing POST data through form onto the same page

查看:103
本文介绍了通过表单将POST数据传递到同一页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的情况。现在我在网页上有一个表格,要求我的访客的信息。我有一个脚本,允许我获取访问者信息并将其附加到链接。



起初,我有一个redirect.php,它允许我将所有信息附加到链接,并使用标题将用户发送到他们的页面。



然而,我想知道是否有可能将此表单数据发送到同一页面并同时显示用户页面。



我希望我有道理。非常感谢。

解决方案

如果理解你的问题可以用很多方法完成,例如使用基于函数的填充。
一种方法是检查表单是否使用 $ _ POST 发布,或者检查隐藏字段$ _POST ['_ submit']。这看起来很乱,但显示基本的方式。

 <?php 
if(!isset($ _ POST ['_ submit '])){
?>

< form action =post.phpmethod =post>
< input type =submit/>
< input name =somevaluetype =text/>
< input name =_ submittype =hiddenvalue =_ submit/>
< / form>

<?php
} else {
echo htmlspecialchars($ _ POST ['somevalue']);
?>

< em>< / em>

<?php}? >

您还需要做其他事情来使代码生成准备就绪,如uisng isset 在您检查的字段上,否则如果有人篡改表单,您将失去通知


I have a rather complicated situation. Right now I have a form on a page that asks for my visitor's information. I have a script that allows me to take the visitors information and append it to a link.

At first, I had a redirect.php that allowed me to append all the information to the link and used a header to send the user to their page.

However, I was wondering if it is possible to send this form data into the same page AND display the users page at the same time.

I'm hoping I make sense. Thanks a lot.

解决方案

this if understand your question can be done many ways, eg using function based fillers. One way is to check if the form has been posted using $_POST or by checking for a hidden field $_POST['_submit']. this looks messy but shows basic way.

 <?php
  if (!isset($_POST['_submit'])) {
 ?> 

 <form action="post.php" method="post">
  <input type="submit" />
  <input name="somevalue" type="text" />
  <input name="_submit" type="hidden" value="_submit" />
</form>

<?php
 } else {
  echo htmlspecialchars($_POST['somevalue']);
 ?>

 <em></em>

 <?php } ? >

There are other things that you would still need to do to make this code production ready like uisng isset on fields your checking against else you will have losts of notices if people tamper with the form

这篇关于通过表单将POST数据传递到同一页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆