0

I have a form on my website (name/address details) on which I want to put a second submit button. To expand a little, the form emails the user details to me and sends the user to Paypal to pay a fixed fee. I would like the second button to do the same except send the user to a Paypal subscribe form to pay the total over 12 payments. As I know very little about coding, I am hoping someone could give me an answer in fairly simple terms as most I have read on here baffle me somewhat.. lol (sorry folks:-)

Here is what I have on my form already -

<form name="form2" method="post" action="paypal.php" onSubmit="return validate()">
    FORM CONTENT
</form>

My button reads - <input type="submit" name="submit" value="pay now"> and I'm using my own button image <img src="imagery/paylogo.jpg border="0">.

I have copied and amended paypal.php with a paypal subscribe script but now need to know the code to make my second button go to that script.

Thanks to all in advance for any advice you can give me.

Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
Pete
  • 1
  • 2
  • Hi Pete, please learn how to correctly format your code samples. You can leave all the markup intact, just make sure the code is in its own paragraph and indented at least four spaces per level, or surround a snippet with backticks (`\`sample\``). What you've posted is really hard to read. – Cᴏʀʏ Mar 08 '15 at 22:36
  • Okay, thanks Cory. Sorry about that but I rushed it a little. – Pete Mar 08 '15 at 22:40
  • possible duplicate of [Two submit buttons in one form](http://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form) – Mark Mar 08 '15 at 23:08
  • In the link above, look at the second highest answer. It shows how you can have two buttons with a `value` property. You can then check this in PHP, and redirect accordingly. – Mark Mar 08 '15 at 23:08

2 Answers2

1

You can use select in your form.

<form name="form2" method="post" action="paypal.php" onSubmit="return validate()">
<select name="pay_option">
  <option value="pay1">Pay 1</option>
  <option value="pay2">Pay 2</option>
</select>
<input type="submit" name="submit" value="pay now">
</form>

and then in your paypal.php

if ($_POST["pay_option"] == "pay1"){

//code for your option 1

}elseif($_POST["pay_option"] == "pay2"){

//code for your option 2

}
Michał Lipa
  • 968
  • 2
  • 12
  • 22
  • Thanks for your answer Michal. It isn't quite what I had in mind but then I didn't quite understand what I needed. After reading some other questions on this site I'm beginning to realise that it's the form that posts and the button that submits. I have duplicated my server side script using a different name (paypal2.php) and thought I could get a button to send the form to the new script whilst retaining the original button to send to the first script (paypal.php). But now I guess that is not possible. Your configuration looks like it might work for me but I'm not sure how to apply it. – Pete Mar 09 '15 at 10:35
  • Glad I could help you. What do you need to know? What is your problem? – Michał Lipa Mar 10 '15 at 22:14
0


I now have a solution to this. A guy wrote a further script for me which is working okay. He added the script - paypalall.php which I have shown below. He also amended the form action to go to this script.

<script><?php
if ($_POST['submit'] == 'Full Payment - Click Here'){
include_once('paypal.php');
} else if ($_POST['submit'] == 'Monthly Payment - Click Here'){
include_once('paypal2.php');
} else {
//exception case! set as full pay
include_once('paypal.php');
} 

I hope others find it useful.
Thanks to all. Pete

Pete
  • 1
  • 2