?
Solved

How to capture data to my database, then redirect user directly to the PayPal screen?

Posted on 2011-04-30
2
Medium Priority
?
224 Views
Last Modified: 2012-05-11
This is the scenario I want:
1. User clicks "Buy Now"
2. User fills out a form with name, phone, etc, then clicks "Pay Now"
3. The form is submitted to my php script where it;
   a) sends some data to my database
   b) redirects user to the Pay Pal Pay Screen
4. User logs in to Pay Pal, or Enters Credit Card info to complete purchase.

Right now, the only way I can achieve this is by having a "middle page" that has a form with the necessary fields for paypal (IE: bussines email, notify url, amount,etc), and a Button. So the user has to click this button to submit the values to Pay Pal so that it can create the Payment screen.

I want to eliminate that middle page and somehow do a redirect to Pay Pal with these POST variables.

I know I can "fake it" by using a javascript to submit the form automatically, so the user wouldn't have to push the button, but isn't there a better way to do this in php?

Thanks for any help :)

Tony
0
Comment
Question by:tonyhhisc
2 Comments
 
LVL 19

Accepted Solution

by:
Greg Alexander earned 2000 total points
ID: 35497928
Try this example, it uses jquery and AJAX.. I have been in your position before and this is what I used to solve it:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script>

	function save_data(){
	
		$.post("insert_into_db_page.php", { 
			amount: ""+$("#amount").val()+"", 
			shipping: ""+$("#shipping").val()+"" 
		},
		function(data){
			$("#real_submit").click();
		});
	}


</script>

<form action="http://paypal.com/whatever_your_link_is" method="post" id="paypal_form">
    <!--You will have all your paypal information here but make sure you have an id on each like the amount example -->
    <input type="hidden" name="amount" id="amount" value="50.00" />
    <input type="hidden" name="shipping" id="shipping" value="10.00" />
    <input type="submit" name="submit" style="display:none;" id="real_submit"/>
    <input type="button" name="submit" value="Go To PayPal" onclick="save_data();" />
</form>

Open in new window

0
 

Author Comment

by:tonyhhisc
ID: 35498004
Ahh, thats a good idea, basically doing 2 Post's at once. I like this, thanks :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question