Forum Moderators: coopster

Message Too Old, No Replies

Save form data to table then do form action

Save data then post to external website

         

Clay213

1:00 am on Feb 16, 2010 (gmt 0)

10+ Year Member



When someone registers for an event on my site, we collect their information on a form and then pass it to our merchant provider who processes the payment and then returns the customer to a page on our site depending on if their card was approved or not.

I have a form that collects more information than what the merchant provider requires. For example: Age. I need to save that extra information in my database and then pass the variables required to my merchant provider.

This is the opening of the form code provided by the merchant:

Code: [Select]
<form id="form" action="https://www.example.com/cgi-bin/dbe/order.pl" method="post" />
I would like to avoid having multiple pages or clicks for the customer. Is that possible? Can I have the form variables saved to my table AND go to the merchant page in 1 click?

Basically I am trying to seamlessly save the customer information and then bring them to the processing URL without requiring the use to click multiple times.

More information on what I am using:

<snip>

What I want to happen is:

1.Customer fills out form.
2. Clicks submit
3. Customer information is entered into table
4. Customer is brought to the order.pl page to enter their credit card
5. Customer clicks submit and their card is approved or declined.

What I don't want is for the customer to need to do anything else between 3 and 4. Does that make sense?

I tried the following

After I hit submit, it shows me the payment gateway and the fields are filled out. The URL in the browser is my site's and when I click 'submit' it tries to bring me to mysite.com/transact.pl which obviously doesn't exist.


extract($_POST);

//set POST variables
$url = 'https://www.example.com/cgi-bin/dbe/order.pl';
$fields = array(
'Total'=>urlencode($Total),
'ePNAccount'=>urlencode($ePNAccount),
'FirstName'=>urlencode($FirstName),
'LastName'=>urlencode($LastName),
'Address'=>urlencode($Address),
'City'=>urlencode($City),
'State'=>urlencode($State),
'Zip'=>urlencode($Zip),
'EMail'=>urlencode($EMail),
'ID'=>urlencode($ID),
'ReturnApprovedURL'=>urlencode($ReturnApprovedURL),
'ReturnDeclinedURL'=>urlencode($ReturnDeclinedURL),
'Phone'=>urlencode($telephone)

);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

[edited by: eelixduppy at 1:25 am (utc) on Feb 16, 2010]
[edit reason] removed specifics [/edit]

rocknbil

8:43 pm on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You almost have it. I'm in a bit of a rush ATM, but here's the cliff notes.

You currently have
1.Customer fills out form.
2. Clicks submit
3. Customer information is entered into table
4. Customer is brought to the order.pl page to enter their credit card
5. Customer clicks submit and their card is approved or declined.


But then, later in your script, you do a curl for a response. Here is what you want to do, or something like it:

1.Customer fills out form. This is on an SSL page, a must. Have them enter the CC info here too.
2. Clicks submit
3. Customer information is entered into table and there is a field called "completed" or "approved" that is set to 0 or false.
4. Do your curl HERE, this is called a "silent post." Send JUST what the processor needs.

$result = curl_exec($ch);

5. Based on the response code you receive in $result,
a) update database to completed, return success response, or
b) return to form with fields populated, indicate an error. It is considered best practice to NOT give them specific details (Declined: invalid credit card number) but by all means LOG this info. Just tell them - in bold red text - the transaction was declined, double check the card number, date, etc.

Now you've eliminated two steps, and the customer has the impression of never having left your site. Whatever you do, do not store their CC info in your database . . . just pass it off.