Jump to content

[SOLVED] 2 submit buttons in one form...is it possible?


MockY

Recommended Posts

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.

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

 

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.

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.