By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

Two different POST actions? Possible?

P: n/a

How do I create a form that two submit buttons, where each one
submits the form input data to a different server?

Consider this situation: I have a form where users can check various
options to subscribe to a service, and each option costs a certain
amount. When the form is submitted, my php script totals up the
options. Fine.

The form has 2 submit buttons: "print invoice" and "pay by credit
card."

The "print invoice" button is for those businesses who can't pay by
credit card but must mail us a check instead; they print an invoice
for their accounts payable department. The php script generates the
invoice based on the form inputs. Easy, no problem.

The problem is "pay by credit card." The total cost from submitted
input fields must be POSTed to a different server: our credit card
processor.

This isn't a problem if the credit card processor accepts the
form input data as a GET string in the URL; all I'd do is
header("Location: $url"); to redirect the user to the credit card
processor page which handles the payment. The problem is I need
to do this by POSTing the form input data, while at the same time
retain the ability to generate invoices from MY server using the
same form.

I can't think of an elegant way to do this except to have two
different payment pages each with their own form. Or maybe force
everybody to generate an invoice as the first step, and after that
point they can choose to pay it by credit card.

-A
Aug 24 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
What I did was to create a dummy action in the post form, and use a
javascript function to swap in a new action and then call the submit
method based on the onclick of different buttons.

-- whit

axlq wrote:
How do I create a form that two submit buttons, where each one
submits the form input data to a different server?

Consider this situation: I have a form where users can check various
options to subscribe to a service, and each option costs a certain
amount. When the form is submitted, my php script totals up the
options. Fine.

The form has 2 submit buttons: "print invoice" and "pay by credit
card."

The "print invoice" button is for those businesses who can't pay by
credit card but must mail us a check instead; they print an invoice
for their accounts payable department. The php script generates the
invoice based on the form inputs. Easy, no problem.

The problem is "pay by credit card." The total cost from submitted
input fields must be POSTed to a different server: our credit card
processor.

This isn't a problem if the credit card processor accepts the
form input data as a GET string in the URL; all I'd do is
header("Location: $url"); to redirect the user to the credit card
processor page which handles the payment. The problem is I need
to do this by POSTing the form input data, while at the same time
retain the ability to generate invoices from MY server using the
same form.

I can't think of an elegant way to do this except to have two
different payment pages each with their own form. Or maybe force
everybody to generate an invoice as the first step, and after that
point they can choose to pay it by credit card.

-A
Aug 24 '06 #2

P: n/a
pe**********@gmail.com writes:
axlq wrote:
>How do I create a form that two submit buttons, where each one
submits the form input data to a different server?

Consider this situation: I have a form where users can check various
options to subscribe to a service, and each option costs a certain
amount. When the form is submitted, my php script totals up the
options. Fine.

The form has 2 submit buttons: "print invoice" and "pay by credit
card."

The "print invoice" button is for those businesses who can't pay by
credit card but must mail us a check instead; they print an invoice
for their accounts payable department. The php script generates the
invoice based on the form inputs. Easy, no problem.

The problem is "pay by credit card." The total cost from submitted
input fields must be POSTed to a different server: our credit card
processor.

This isn't a problem if the credit card processor accepts the
form input data as a GET string in the URL; all I'd do is
header("Location: $url"); to redirect the user to the credit card
processor page which handles the payment. The problem is I need
to do this by POSTing the form input data, while at the same time
retain the ability to generate invoices from MY server using the
same form.

I can't think of an elegant way to do this except to have two
different payment pages each with their own form. Or maybe force
everybody to generate an invoice as the first step, and after that
point they can choose to pay it by credit card.
What I did was to create a dummy action in the post form, and use a
javascript function to swap in a new action and then call the submit
method based on the onclick of different buttons.
Please don't top-post. I've corrected it above.

Also, Javascripting a critical part of a website is always a Bad
Idea. Many people, such as myself, have browsers that don't support
Javascript. Many people disable Javascript in their browsers to
avoid popups, ads, etc.

A better solution to this would be to create a confirmation page
for the credit card purchase which has an additional submit button
that goes only to the credit card company.

The confirmation page can be the invoice page, except that it checks
which button was clicked and either displays an invoice or a
confirmation (or both).

--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 25 '06 #3

P: n/a
In article <11**********************@h48g2000cwc.googlegroups .com>,
<pe**********@gmail.comwrote:
>What I did was to create a dummy action in the post form, and use a
javascript function to swap in a new action and then call the submit
method based on the onclick of different buttons.
I prefer not to rely on javascript for something this critical.
Javascript is fine for user convieniences such as form data
validation and expandable list trees, but the web site should
still function properly without it. A Lynx user should be able to
navigate through the form.

Using the invoice as a confirmation page before credit card purchase
seems like the best approach. Not what I want exactly, but it will
work.

-A
Aug 25 '06 #4

P: n/a
*** Andrew Poelstra escribió/wrote (Fri, 25 Aug 2006 14:25:01 GMT):
Many people disable Javascript in their browsers
Many developers love to think that users do so, but they don't :)

But of course JavaScript is the worst tool for critical tasks. Among many
other reasons, because developers who abuse JavaScript tend to be terrible
coders and their scripts fail in browsers that are not Internet Explorer
(and pretty often in IE itself). Good JavaScript coders just leave
scripting for auxiliary tasks.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 25 '06 #5

P: n/a
NC
axlq wrote:
>
How do I create a form that two submit buttons, where each one
submits the form input data to a different server?
You can't. Just separate the forms. Like this:

<table>
<tr>
<td><form method="POST"
action="http://www.yoursite.com/path/printinvoice.php">
<input type="hidden" name="custid" value="Customer_ID">
<input type="hidden" name="date" value="Date_of_Invoice">
<!-- more fields if necessary -->
<input type="submit" value="Print Invoice">
</form>
<td>form method="POST"
action="https://www.yourpaymentprocessor.com/path/">
<input type="hidden" name="merchantID" value="Your_Merchant__ID">
<input type="hidden" name="amount" value="Amount_of_Payment">
<!-- more fields if necessary -->
<input type="submit" value="Pay by Credit Card">
</form>
</table>

The invoice printing script and the payment gateway are likely to
require different sets of data anyway...
Or maybe force everybody to generate an invoice as
the first step, and after that point they can choose to
pay it by credit card.
Not a bad idea, either.

Cheers,
NC

Aug 25 '06 #6

P: n/a
"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.comwrites:
*** Andrew Poelstra escribió/wrote (Fri, 25 Aug 2006 14:25:01 GMT):
>Many people disable Javascript in their browsers

Many developers love to think that users do so, but they don't :)
Okay, I'll bite. I'm a user and I use lynx. I also disable Javascript in
all my GUI-browsers so that I don't have to see popups and other crap.

Of course, you may argue that as a developer I don't count as a "user".
:-)
But of course JavaScript is the worst tool for critical tasks. Among many
other reasons, because developers who abuse JavaScript tend to be terrible
coders and their scripts fail in browsers that are not Internet Explorer
(and pretty often in IE itself). Good JavaScript coders just leave
scripting for auxiliary tasks.
That's definitely true; I have a grammar checker written in Javascript
(no, it doesn't work well enough for me to link to it here), and it takes
several seconds to parse only a few kilobytes of text. I have no idea what
it'd do if transferred to IE (there's virtually no IO, so I'd assume that
it would be fine).

Whereas the logic, if transferred to C, would run through thousands of
times that much text in as little time. On a processor only 10% as
powerful.

--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 25 '06 #7

P: n/a
In article <11*********************@b28g2000cwb.googlegroups. com>,
NC <nc@iname.comwrote:
>axlq wrote:
>How do I create a form that two submit buttons, where each one
submits the form input data to a different server?

You can't. Just separate the forms. Like this:
[snip]

Then I have redundant fields that need to be filled in twice. That's
exactly what I was trying to avoid. I wanted one form with two
submit buttons, each sending the data to a separate server.
>The invoice printing script and the payment gateway are likely to
require different sets of data anyway...
Why? I just use the payment gateway POST data to generate the
invoice.
>Or maybe force everybody to generate an invoice as
the first step, and after that point they can choose to
pay it by credit card.

Not a bad idea, either.
Based on the responses, it looks like that's the way to go.

-Alex
Aug 25 '06 #8

P: n/a
NC
axlq wrote:
>
The invoice printing script and the payment gateway are
likely to require different sets of data anyway...

Why? I just use the payment gateway POST data to generate
the invoice.
Why would you ever do that? You are giving away your (or your
customer's) internal information, which the payment processor is under
no obligation to safeguard. The only information you should give the
payment processor is that which is required to process payment (credit
card information and the amount). The rest (items and quantities)
should be kept internal.

Cheers,
NC

Aug 25 '06 #9

P: n/a
Many developers love to think that users do so, but they don't :)

Of course, you may argue that as a developer I don't count as a "user".
:-)
Both of these are very true. I used to work for a government office in
Finland. There was about 2500 employees. If I remember correctly, in IE
javascript was disabled as default. And stayed that way for most users,
naturally.

Aug 26 '06 #10

P: n/a

Alvaro G. Vicario wrote:
*** Andrew Poelstra escribió/wrote (Fri, 25 Aug 2006 14:25:01 GMT):
Many people disable Javascript in their browsers

Many developers love to think that users do so, but they don't :)

But of course JavaScript is the worst tool for critical tasks. Among many
other reasons, because developers who abuse JavaScript tend to be terrible
coders and their scripts fail in browsers that are not Internet Explorer
(and pretty often in IE itself). Good JavaScript coders just leave
scripting for auxiliary tasks.
I wouldn't say that. When implemented correctly client-side code
usually improves the user experience. I think people just need remember
a key advantage of (and motivation for) server-side programming: you
control the environment where the code runs. Client-side code is hard
to QA because there are many variables you can't control. Testing on
multiple platforms and configurations is tedious and could require more
manhours than writing the code in the first place.

Often when I hear the word AJAX I feel like beating the speaker over
the head with a big wooden spoon.

Aug 26 '06 #11

P: n/a
axlq wrote:
This isn't a problem if the credit card processor accepts the
form input data as a GET string in the URL; all I'd do is
header("Location: $url"); to redirect the user to the credit card
processor page which handles the payment. The problem is I need
to do this by POSTing the form input data, while at the same time
retain the ability to generate invoices from MY server using the
same form.
You can redirect a POST with the HTTP status code 307. That only works
well with Internet Explorer though. Firefox would pop up a warning
message. Don't know if the issue's been fixed or not.

Aug 26 '06 #12

P: n/a
*** Chung Leong escribió/wrote (26 Aug 2006 12:01:11 -0700):
You can redirect a POST with the HTTP status code 307. That only works
well with Internet Explorer though. Firefox would pop up a warning
message. Don't know if the issue's been fixed or not.
Firefox 1.5.0.6 pops up a warning message prompting whether you want to
resubmit the data to the new page.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 27 '06 #13

P: n/a
On 2006-08-24 11:57:46 -0600, ax**@spamcop.net (axlq) said:
>
How do I create a form that two submit buttons, where each one
submits the form input data to a different server?
It's not too hard. Have two submit buttons and then choose your action
based on which one was chosen.

==============================
form
==============================

<form action="handler.php" method="post">
Order form stuff
<input type="submit" name="invoice" value="Print invoice" />
<input type="submit" name="creditcard" value="Pay via credit card" />
</form>

==============================
handler.php
==============================

<?php
if (isset($_POST['invoice'])) {
Print an invoice
}
if (isset($_POST['creditcard'])) {
Pay via credit card
}
?>

If your using two different servers as your post suggests you can just
redirect the data to the correct location in the if() statement,
otherwise just add the appropriate code or include the appropriate file
in the if(). Hope that helps.

Aug 29 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.