473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Two different POST actions? Possible?


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
13 1962
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
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
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
*** 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
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
"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
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
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
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

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
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
*** 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: NotGiven | last post by:
Some have said to used GET for all quesries except those that manipulate/change a database. Some say use POST to quasi-hide parameters. Your thoughts?
1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
8
by: Laith Zraikat | last post by:
I am trying to invoke a post request from code behind of an asp.net page using "WebClient" object, and I want the user to be redirected to the action url as well. So far Ive been able to send...
40
by: rdemyan via AccessMonster.com | last post by:
I have two databases, db1 and db2, with the same table, TableA. I want to select the records from TableA in db1 that have a LAST_UPDATE SomeDate. Then I want to get the identical records in TableA...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
3
by: squishywaffle | last post by:
Greetings, I've been trying to figure out if it's possible to attach a Python script to an action via Mac OSX Leopard's File Actions system. I'm wanting to call a Python script every time a file...
9
by: Carl Johansson | last post by:
If a multithreaded .NET application is executed on a computer with a multicore processor. Will the application automatically run the threads on different processor cores? Regards Carl Johansson
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.