-1

I have currently created a form with two different buttons and i would like both buttons to do a different function, the first button is the Pay on Finance button and when that is pressed i would like it to divide the value the user entered into the text box by 12 and then echo "Your monthly payment will be result". and then for the second button which is Pay Full Amount it would multiply the value by 0.2 and then echo "please pay the deposit of result and pay the rest next week"

I have attempted this myself but don't fully understand what to do to get this working, i have read up a little on functions within php but i am a beginner and not too sure what i am doing with it, any help would be most appreciated.

Here is the code of the form I currently have.

<div id="form">
<form action="nissan350z.php" method="post">

   <center> <input type="text" name="percent" id="percent" />
  <input type="Submit"  value="Pay on Finance"> 
  <input type="Submit"  Value="Pay Full Amount">  </center>

</form>
Petty13579
  • 35
  • 4
  • Here [link][1] is an example how to handle two submitt buttons on a form [1]: http://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form – KB9 Aug 30 '13 at 13:18
  • Take a look at [this](http://stackoverflow.com/a/547848/2596762) answer. Provides 2 ways of getting what you need. – Rahul Dabas Aug 30 '13 at 13:24
  • Why does this question look familiar(?) – Funk Forty Niner Aug 30 '13 at 13:26
  • *"Here is the code of the form I currently have."* Is that it? Why should we write code for you? This question looks awfully familiar from about 2 weeks ago. May not be you; however you need to provide code that you tried. **We help, we don't build.** – Funk Forty Niner Aug 30 '13 at 13:30

3 Answers3

1
  <input type="Submit"  name="Finance" value="Pay on Finance"> 
  <input type="Submit"  name="Full" Value="Pay Full Amount">

Notice I have added the name attribute. then validate with

if (isset($_POST['Finance'])){
 //User pressed Finance
} 

if (isset($_POST['Full'])){
 // User pressed Full
}
Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
1

Give your submit buttons a name:

<input type="submit" name="pay_on_finance" value="Pay On Finance">
<input type="submit" name="pay_full_amount" value="pay full amount">

on your nizzan350z.php you check which button is clicked by

if (isset($_POST['pay_on_finance'])) {
    //Do Something
} else if (isset($_POST['pay_full_amount'])) {
    // Do something else
}
MrSkippy
  • 348
  • 4
  • 17
0

You can do the same things by using php and javascript.

Modify HTML code in your current file which you mentioned above,

<input type="Submit"  name="Finance" value="Pay on Finance"> 
<input type="Submit"  name="Full" Value="Pay Full Amount">

In your nissan350z.php file write,

<?php
if (isset($_POST['Finance'])){
  $result=str_replace(",","",$_POST['percent'])/12;
  echo $result;
  echo "Your monthly payment will be result";
} 

if (isset($_POST['Full'])){
  $result=str_replace(",","",$_POST['precent'])*0.2;
  echo $result;
  echo "please pay the deposit of result and pay the rest next week";
}
?>
Yatin Trivedi
  • 661
  • 6
  • 9
  • just write echo $result; on the very next line – Yatin Trivedi Aug 30 '13 at 13:28
  • on here you have put /2 is that divide by 2 or divide by 0.2 because thats what i need so if it isnt how would i put that in just type .2 would that work? – Petty13579 Aug 30 '13 at 13:30
  • okay thanks i had managed to work it out anyway xD although i have a minor quibble, if i enter 80,000 and press the finance button it displays 6.6666667 roughly, which is obviously wrong but when i enter 80000 it displays the correct number being something like 6666,6666667 is there a way i can make it so it works with a comma as well? – Petty13579 Aug 30 '13 at 13:38