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:
<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:
<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.
source share