在 php 中创建一个表单来保存用户提供的信息,并将其插入另一个可打印的页面

2022-01-06 00:00:00 php webforms populate

我正在开发一个网站,该网站可以为网站用户提供预先写好的信件,以便将其发送到某个地方.用户所要做的就是填写表格并点击继续,然后用户在表格中输入的任何信息(例如姓名)都会被插入到可打印页面上的预先写好的信件中.一个基本的例子是,如果表单要求输入姓名,那么你点击继续,在可打印的页面上,它会说:

I'm working on a site that gives the users of the site pre-written letters to send to places. All the user has to do is fill out a form and hit continue, then whatever information the user put into the form (like name for example) gets plugged into a pre-written letter on a printable page. A basic example would be if the form asks for Name then you hit continue, on the printable page, it would say:

我叫扎克.

我使用的是基于 php 的内容管理系统,所以它应该在 php 中.我知道这对于那些知道如何去做的人来说是一件非常简单的事情,不幸的是我不知道.预先感谢您的帮助!

I'm using a php based content management system so it should be in php. I know this is a very simple thing to do for those who know how to do it, I unfortunately don't. Thank you in advance for your help!

推荐答案

假设你有这个表格:

<form action="preview.php" method="POST" >
<input type="text" name="name" />
<input type="submit" value"Print" />
</form>

当您点击提交时,所有字段的值(在本例中为输入,还有 textarea、选择等)将保存到 POST 数组(或 GET,如果您设置了 method="GET").

When you hit submit, the values of all the fields (input in this case, but also textarea, selects, etc) are save to the POST array (or GET if you set method="GET").

您可以使用如下代码从 preview.php 页面(在此示例中您要打印名称的位置)访问 POST 和 GET 数组:

You access the POST and GET arrays from the preview.php page (where you want to print the name in this example) with code like this:

<?php
  $name = $_POST['name'];
?>
<p>Hi, my name is <strong><?=$name?></strong>.</p>

相关文章