Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2649
  • Last Modified:

PHP multi-form process & submit

I have a PHP page with two forms.  One form collects registration information and performs (server side) validation of that form.  When the form validates, it is presented to the visitor as a summary.  When this occurs, a second form (with hidden values) is also populated with information to submit to PayPal to collect registration fees.  

What I need to do is allow the user to hit one "submit" button of some sort and have the information from the registration form be sent by e-mail to an address, and the PayPal form data be submitted to PayPal to collect payment.

My basic question is whether there is a way to "submit" form data via pure PHP code.  Javascript isn't an option.
0
Syncubus
Asked:
Syncubus
1 Solution
 
Marcus BointonCommented:
The problem is that the form that you post to paypal needs to go directly to paypal, so your script doesn't get a look in. The way I deal with this is not to email the results until the transaction returns from paypal, at which point you know that the transaction has been completed. otherwise you don't know if the transaction was completed or not and you'll generating excess emails.

Alternatively, submit all the info to your script, send the email, then redirect to paypal with all the params attached. I think you'd have to do that using a GET, and paypal submissions may be too big to work reliably. I'm not sure how you can redirect using a POST.

CURL is not an option as it denies user access to the web interface of paypal.
0
 
SyncubusAuthor Commented:
I have discovered the code I was looking for on PayPal's site in their developer's documentation.  It is built writing to sockets.  

e.g. (super condensed):

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
0
 
Marcus BointonCommented:
This is more or less what I was referring to when I mentioned CURL, which can do that kind of thing more easily than plain sockets will, but I'm pretty sure that's not what you're asking for. The problem I was referring to is that if you start a paypal session like that, you can't hand over interaction to the user later on, i.e. once you have started talking to paypal via your script, you can't let your client carry it on from the browser. It's as if you'd logged into a site, stuck a few things in a shopping basket and then expect me to take over the session in a different browser on a different computer - it's very unlikely to work, let alone securely.

The usual situation (as I'm guessing you have) is that you pre-populate the paypal-specific fields in your form with what they have bought, prices, quantities, your paypal ID etc. then hand it over to paypal, where the user enters their paypal login details, completes the transaction and then returns to your site.

As I said, the problem with this arrangement is that you don't get a look-in as you pass the final data to paypal, though paypal will 'call you back' when it has finished. Also, are you sure you want to send an email when this form is submitted as it does not guarantee that the transaction is complete, only that the purchase info has been transferred to paypal - they may fail to log in, or just give up on the transaction. You will have to check your emails against paypal's transaction logs in order to eliminate any abandoned transactions.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SyncubusAuthor Commented:
Squinky,
Thank you for your suggestions.

Yes, I am absolutely sure this is the way things need to be handled, as the registration infrmation is more data than PayPal can (or needs to) handle.  PayPal only needs the total.  I thank them on the return page.

Thank you or your efforts.  FYI, the PayPal developers documentation gives some good PHP code examples, in case you're loking for some.
0
 
Marcus BointonCommented:
Fair enough. In that case, I'd recommend that you do look at CURL instead of fsockopen - it will be simpler, faster and more reliable. It will also cope with redirects that paypal may throw at you that are very complex to handle manually, SSL, cookies, etc.

http://www.php.net/manual/en/ref.curl.php

Failing that (for example if you don't have curl compiled in), you can use PEAR's HTTP_Client class:

http://pear.php.net/package/HTTP_Client

Either way you will get much better reliability than fsockopen.
0
 
SyncubusAuthor Commented:
Actually, I ended up with two pages.  A confirmation screen that mails the results of the registration (with all of its information), and another page that builds the PayPal form [click here to pay].  
0
 
OzzModCommented:
Closed, 500 points refunded.
OzzMod
Community Support Moderator (Graveyard shift)
0
 
wickwoodCommented:
Syncubus, could you post where exactly you found that code from the PayPal developers section?  I have exactly the same problem, and i would like to see what PayPal says but can't find what you found.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now