Skip to main content
September 2, 2006
Question

PHP Preview form before submitting or printing

  • September 2, 2006
  • 2 replies
  • 1952 views
Students in one of my classes are completing their homework online and submitting it to a MySQL database. So far, it works well. But they can't preview their work before submitting it, and if they try to print from the form, the printed font is extremely small.

The solution seems to be a preview button that would bring up a separate form with the questions and their answers neatly formatted and reading for printing. There could either be a submit button on the second form that would submit the form to the database, or students could close the second form and submit the first one. I'd like to write a generic script that I can just require_once in the header of any homework assignment page.

I've looked at previous posts in this forum dealing with this question, and I've also searched for information on websites and in PHP forums. I find a few details, but not enough to help. For example, I find that I can use hidden fields or session variables to transfer the values of the various fields from one form to another; but the syntax is a little hazy. I'm also not sure how to transfer the fixed text I place on the page; that is, the homework problems themselves. To clarify my question, here is what a page might look like:

Assignment 3

Question 1. Go to [web link] and look [this] up. Summarize your findings.
[Textarea1]
Question 2. Take this information and compare it with what you read [here]. What discrepancies do you find, and how do you account for them?
[Textarea2]
[And so on through several questions.]

If I'm writing a generic script to include in the header of each assignment page, I'm not sure how to capture the text of each homework question and transfer it to the preview page, and I'm also not sure of what syntax to use to transfer the contents of each textarea.

Many thanks in advance for your help.

Joe Herl
This topic has been closed for replies.

2 replies

September 4, 2006
just display the form conditionally, like:

<!--your content here-->
<?php
if(isset($_POST['submit'])){
//show review of form data
}else{
//show form
}
?>
September 4, 2006
what i usually do to make things easy is to name each database field the same as the form control. then you can print the form data by sorting through the $_POST array:

sample:
<?php
$arr['one']=1;
$arr['two']=2;

foreach (array_keys($arr) as $field) {
echo "<p>".$field.'='.$arr[$field]."</p";
}
?>

from here you could put a button that allows them to reopen their form or submit their work.

if you need any more help let me know.
September 4, 2006
Thank you. That maks a lot of sense. Any idea how I might get my original HTML text onto the preview page? Since I'd like to make this a generic script, that text will differ with each page. Could this perhaps be a CSS question?

Joe