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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.