MockY Posted November 14, 2007 Share Posted November 14, 2007 I built a working form script that emails me the information the user entered in a css styled form. As well as a send button, I would like to have a print button, that instead of emailing me the information entered, it pulls the same result form that would be emailed to me, in a new window so that the user can view the result and then print it. Is this even possible? And if not, what are my alternatives? As far as I know, only the submit button collects the data in the fields and puts it into the php variables and then does something with the results. Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 14, 2007 Share Posted November 14, 2007 Totally possible. Just give the each button a different name <?php if(isset($_POST['submit1']) ) { //email it } else if(isset($_POST['submit2']) ) { //display for printing } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 14, 2007 Share Posted November 14, 2007 The way I do it is to test on the value of the submit button, not the name. This way all the submit buttons can have the same name and you can use a "switch" statement to execute the correct code. <form method="post"> <input ....> <input type="submit" name="submit" value="Display"> <input type="submit" name="submit" value="Print"> </form> <?php if (isset($_POST['submit'])) switch ($_POST['submit']) { case 'Display': // // code for this submit // break; case 'Print': // // code to Print // break; } ?> Ken Quote Link to comment Share on other sites More sharing options...
MockY Posted November 14, 2007 Author Share Posted November 14, 2007 Thanks for the responses, but how do I go about to have the results pop up in another window? One button should simply email the form to me, and the other one should make the result form pop up and the user can from there manually print it. The reason for that is that when it is displayed on the website, a printout includes the menus and such from the site and not only the form. I guess this requires javascripts. Regardless, I'll start changing the code to what you guys suggested so far. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 14, 2007 Share Posted November 14, 2007 I would suggest that you look at using CSS to limit what is printed, instead of using a pop up window, that way your users can just use the normal print mechanism on their browsers. I use it all the time and it works well. Ken Quote Link to comment Share on other sites More sharing options...
MockY Posted November 15, 2007 Author Share Posted November 15, 2007 I used the switch statement you suggested along side with restrictive CSS and it works perfectly. Many many thanks! Quote Link to comment Share on other sites More sharing options...
MockY Posted November 15, 2007 Author Share Posted November 15, 2007 I noticed now however that it does not work on my web host. It only works on my local server. Is this a php4 vs php5 issue? What happens when executed is that it shows a blank page instead of the form. Sending it via email works just fine, but the display option shows up blank. I assume that this is because the host is running on php4 but I might be wrong. EDIT: Nevermind, I'm stupid. I changed the value of the button without thinking. It works just fine. Problem solved. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.