使用PHP将表单数据从一个网页传递到另一网页 [英] Passing form data from one web page to another with PHP
问题描述
我在这里发现了几个类似的问题,但是从答案中我没有得到应该如何工作的全貌.
i found few similar questions here but from answers i didn't get the whole picture of how should work.
我在页面中有一个订阅表单:
I have a subscription form in a page:
<form method="post" action="index.php/register">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
当用户单击用户提交按钮时,将导致页面具有完整的注册表单,在这里我需要用前一页表单发送的数据填充几个字段.这是第二页形式的一些字段的预览:
when a user a user click the submit button is lead to a page with the full registering form, where i need to have few fields populated with the data sent from previous page form. this is a preview of few fields from the form of the second page:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
php不是我的强项,所以如果您可以更详细地回答,对我来说是很棒的.
the php is not my strong point, so if you can be more detailed in answer is great for me.
谢谢!
推荐答案
出于安全原因,我要说的是,不要像人们所描述的那样使用Get方法"$_GET[]
",保持POST不变.
I would say for security reasons, do not use Get method "$_GET[]
" as people described, keep POST as you have it.
您需要在register/页面上做的所有事情就是使用POST方法获取所有传递的值,并将它们填充到HTML中.因此,第二种形式应如下所示:
All you need to do on register/ page is get all the values passed on using the POST method and populate them into your HTML. So the second form should look like:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>First Name</label>
<input type="text" id="first_name" name="first_name" value="<?=$_POST[first_name]?>" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" value="<?=$_POST[last_name]?>" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" value="<?=$_POST[email]?>" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" value="<?=$_POST[address]?>" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
以上,我使用的是"echo"和php标记的简写,如果您没有在php.ini中启用该标记,请将"更改为"; ?>
.另外,脚本不会填充确认"电子邮件,因为我认为您希望用户重新输入该电子邮件.
Above, I am using shorthand version of "echo" and php tags, if you do not have that enabled under php.ini, please change "" to "; ?>
. Also, script will not populate "confirm" email as I assume you would like the user to retype that.
应该这样做.
这篇关于使用PHP将表单数据从一个网页传递到另一网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!