I've looked through the posts here and other sites, as well as my Dummie's Guide level books, and I can't get a clear answer on how to have a preview page on my php form. So maybe it's not so simple?

I started out with Php Form Generator and have customized it from there. I can get it to return a thank you page, email the sumitted results, and post it to mysql. But I can't figure out how to do an intermediate step of allowing users to preview their submission before actually submitting it? I figured to just let them hit "back" to edit for simplicity, at least for now.

Just shoving a preview button into the html form does take me to a preview page generated by the process.php, and I did put a submit button there. But I can't make it actually submit from there. I've also rearranged the script so the processes I want done afterwards are listed after, but that doesn't seem to do it. And it shows all that "after" coding too.

I've found different references to "registering variables", "session variables", multiple processing files, none of which were written as complete answers to how to make a basic preview page. I'm getting horribly confused what I need to research at this point.

Many of my users don't have javascript turned on, so hopefully a fully php solution is out there. Can anyone please point me in the right direction?

May you all have a very merry xmas (or holiday of your choice), eat too much, party too hardy, and have a great 2006! (I'll be playing with php, thank you, hehehe).

    You could have two submit buttons: one to submit and one to preview. The preview one would take you to preview page. On the preview page, you could show the preview and store the variables in hidden input fields (<input type="hidden" />). From that page, users could choose to either submit or edit again.

    Another option is to have the editing page refresh to itself when the preview button is clicked, using <form action="<? echo $_SERVER['PHP_SELF']; ?>">. That way, you could show the preview on top, and have editing controls on the bottom, and you don't need to worry about hidden input fields.

    Hope this helps, if you need any clarification, just ask.

      You could have two submit buttons: one to submit and one to preview. The preview one would take you to preview page. On the preview page, you could show the preview and store the variables in hidden input fields (<input type="hidden" />). From that page, users could choose to either submit or edit again.

      This is just about exactly what I'd like to do, thank you!!

      I need two php generated pages. First for preview, then they hit submit there, and get the second for thank you. Or go straight to submit and get thank you page. Can I do that in one process.php script? Is there an if-else statement that will do that for me? I haven't been able to find an example of one. (if preview is selected, do this, if submit, do that...). I do miss ye olde Basic subroutines: "if x then go to y". But I think that's pretty much what I seem to need, a preview subroutine.

      Would the hidden values on the preview need different variable names? Or else how does the script know not to submit them? When I tried adding a preview tag to the form, input type=submit name="preview" value="Preview", it still submitted the info. I obviously am just flailing so far, but I'm learning!!

        You would use:

        <?php
        if($_POST['preview']) {
            //show preview
        } elseif($_POST['submit_without_preview']) {
            //submit data without preview
        }
        ?>
        

        The hidden values on the preview page would not need different variable names. Show your code and you'll be able to be better helped.

          So it does exist!!!!

          Ok, I need to edit the parts that would be useful to show here first, it's too eye-crossing if I would post the whole script. I'm such a noob, I'm afraid to actually delete anything in the scripts so I just remark it out.

          I also just realized that I have some fantastico scripts available on one of my sites, most of which are php freebie license type stuff. If I install one or two, I might be able to pick out something like the if/else statement you mention here from the source code, with any luck. I'll keep you posted. You may have set me on the right track here 😃

            5 days later

            Doing a bit more reading and using hidden values as you suggested, I got it to preview before submitting!! I ended up not trying to have one process.php file do two actions. I have no idea if these additions are hard on the server processors or what, but it's working.

            HTML form now has a button named "preview".
            <input type=submit name="preview" value="Preview">
            No button named submit since I want to at least try to get users to read what they wrote first. It goes to process.php where I removed all the mysql insert stuff and email coding, and redid the thank you page coding to be a preview. The items in bold are my additions and carry the data to the next, final page where that second php page puts the info into the database and sends out the email (btw, this is a donation form for a charity auction):

            <form enctype='multipart/form-data' action='processtest2.php' method='post'>
            <br>
            <B>Please preview your information before submitting it. </b>
            <br> <br>
            <table width=50%>
            <tr><td><?php echo $date; ?><input type=hidden name='date' value='<?php echo $date; ?>'>
            <tr><td>Your Name: </td><td> <?php echo $donorfirst; ?> <?php echo $donorlast; ?>
            <input type=hidden name='donorfirst' value='<?php echo $donorfirst; ?>'><input type=hidden name='donorlast' value='<?php echo $donorlast; ?>'> </td></tr>
            <tr><td>Your Email: </td><td> <?php echo $demail; ?>
            <input type=hidden name='demail' value='<?php echo $demail; ?>'></td></tr>

            etc etc etc with all the fields and table tags until:
            Please hit your back button to edit <br>
            <input type=submit value='Submit your item'>

            It now pulls up processtest2.php where now the thank you page really is a thank you page. The inputted items echo again for the donor to print out. This is where I left in the mysql and email coding so those do their thing now too. And it does 🙂

            Clear as mud?

              22 days later

              Hi,

              I wanted to use the preview option suggested

              <form action="<? echo $_SERVER['PHP_SELF']; ?>">. 

              without creating additional files or scripts. Is this possible ? Can I amend just

              <form method="post" action="enq1.php?userid=<? echo $userid ?>"> 

              to read as

              <form method="post"  action="<? echo $_SERVER['PHP_SELF']; ?>&userid=<? echo $userid ?>"> 
              
              <form method="post" action="enq1.php?userid=<? echo $userid ?>"> 

              I realise though there needs to be a way for the script to know which of the 2 forms to process so I wonder if this solution is possible at all without creating another script .

              <form method="post" action="enq1_preview.php?staffid=<? echo $staffid ?>"> 
              
              and then when one hits a submit button in enq1_preview.php, it will submit to enq1.php as below :
              
              <form method="post" action="enq1.php?userid=<? echo $userid ?>"> 
              
              
              
              <? include("protect.php"); ?> 
              
              <form method="post" action="enq1.php?userid=<? echo $userid ?>"> 
                 </td><td><select name="customer"><option value="">[Select One] 
                    <?php 
              mysql_connect("localhost", $dbname, $dbpasswd ) 
                      or die ("Unable to connect to server."); 
              mysql_select_db($database) 
                      or die ("Unable to select database."); 
              $result = mysql_query("SELECT DISTINCT `Company` FROM `Customers_List` ORDER BY `Company` asc "); 
              if ($myrow = mysql_fetch_array($result)) { 
                do { 
                  printf("<option> 
                    %s", $myrow["Company"]); 
                } while ($myrow = mysql_fetch_array($result)); 
              } 
              ?></select></td></tr> 
                      </td><td>Machine:</td><td> 
              <select name="mach"><option value="">[Select One] 
                    <?php 
              mysql_connect("localhost", $dbname, $dbpasswd ) 
                      or die ("Unable to connect to server."); 
              mysql_select_db($database) 
                      or die ("Unable to select database."); 
              $result = mysql_query("SELECT * FROM `Machines_handled_by` WHERE userid='$userid' ORDER BY `Name` asc "); 
              if ($myrow = mysql_fetch_array($result)) { 
                do { 
                  printf("<option> 
                    %s", $myrow["Name"]); 
                } while ($myrow = mysql_fetch_array($result)); 
                  echo "</select>\n"; 
              } else { 
                  echo "Sorry, no records were found!"; 
                  echo "</select>\n"; 
              } 
              ?></td></tr> 
                      </td><td>MetDate:<input type="text" size="12" name="met_date"></td></tr> 
                      </td><td>Category:<select name="category"> 
                      <option value="">[Select One] 
                      <option value="A">A: 
                      <option value="B">B: 
                      <option value="C">C: 
                      <option value="D">D: 
              </select></td></tr> 
              <input type="submit" value="Proceed"> 
              </form> 
                Write a Reply...