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

StackOverflow https://stackoverflow.com/questions/4605471

  •  25-09-2019
  •  | 
  •  

Question

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:

Hi, my name is Zach.

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!

Was it helpful?

Solution

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>

OTHER TIPS

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? :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top