Various POST options for the form, then data transfer

I am currently working on a site using PayPal for Checkout. I would also like to include a strip, so there may be a "checkout with stripe" button at the bottom of the form.

<form method="POST" id="form1" > <select id="udidSelect" onchange="udidPrice(this)"> <option value="invalid" disabled="disabled">Choose Package</option> <option value="udid">UDID Registration</option> <option value="profile">UDID Registration & Free Unlimited Apps (Provisioning Profile)</option> </select><br /> <br /> <input type="text" placeholder="Name" /><br /> <br /> <input type="email" placeholder="Email" /><br /> <br /> <input type="text" placeholder="UDID (40 Characters Long)" name="os0" /> <br /> <input type="hidden" name="on0" value="UDID"> <br /> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" id="udidbuttonID" value="9PSTCESRS3FSG"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" value="PayPal" onclick="submitForm('https://www.paypal.com/cgi-bin/webscr')" style="float:right;"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> 

Now I would like to have a PayPal button at the bottom of the form and a Stripe button at the bottom of the form. And if the user clicks on the stripe button, he will move them to the next page and VIEW the information entered on this page. I'm not sure how to do this, and I'm also not sure how to have different message options for the form. (Sorry, I'm kinda new to this.)

On the strip check page, you can also request information that has been submitted from the previous form. Will it be something like this?

 <input type="hidden" name="somedata" value="<?php echo $_POST['somedata']; ?>" /> <input type="hidden" name="otherdata" value="<?php echo $_POST['otherdata']; ?>" /> 
+4
source share
2 answers

If I read your question correctly, you want the form to go to different pages depending on whether the user clicked on Stripe or Paypal.

You can use JavaScript / jQuery to change the action attribute of the form:

 <!--HTML--> <button onClick="setFormAction('stripe')">Stripe</button> <button onClick="setFormAction('paypal')">Paypal</button> //Javascript function setFormAction(which) { if (which == 'stripe') { //Change 'stripe.php' to the proper URL document.getElementById('form1').action = 'stripe.php'; } else { document.getElementById('form1').action = 'paypal.php'; //Change this also } //Finally, submit the form document.getElementById('form1').submit(); } 

Or, more understandably, a jQuery solution:

 <!--HTML--> <button id="stripe">Stripe</button> <button id="paypal">Paypal</button> //Javascript $('button#stripe').click(function() { $('form#form1') .attr('action', 'stripe.php') //Change to proper stripe URL .submit(); }); $('button#paypal').click(function() { $('form#form1') .attr('action', 'paypal.php') //Change to paypal URL .submit(); }); 

On the next page, you will do what you said earlier:

 <input type="hidden" name="somedata" val="<?php echo $somedata; ?>" /> 

Always deactivate user-entered values ​​before echoing them on the page (therefore the variable $somedata , not $_POST['somedata'] .

An alternative to hidden input fields are sessions. It's much easier to handle once you get it.

+1
source

Add another line:

test.php is the page where you want to submit this form

 <input type="button" border="0" value="Pay with Stripe" onclick="submitForm('test.php')"> in test.php you can get the values like this: <input type="hidden" name="test" value="<?php echo $_REQUEST['test'] ?>"> 
+1
source

Source: https://habr.com/ru/post/1445364/


All Articles