Make a form in php that saves information a user gives, and plugs it into a another printable page

故事扮演 提交于 2019-12-02 12:22:12

Suppose you have this form:

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

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").

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>

in your first page:

<form action="letter.php" method="get">
<input type="text" name="personsName"></input>
<input type="submit" value="submit">
</form>

Then in letter.php do this:

<?php
$firstname = $_GET['personsName'];
echo "My Name is" .$firstname;
?>

That ok? :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!