How to add up value via function - PHP - php

I am trying to create a function that add up number to a given variable each time a button was click.
I have 4 buttons: farm, cave, house, casino
So what I am trying to achieve here is I need to send the random numbers generated by the buttons to a variable that will add up all of the SCORE on the "YOUR GOLD" section. So let's say I click the farm and the cave button so there will be 20 for the cave and 15 for farm for a total of 35 gold already.
Here's my form.php
<div class="wrapper">
<div id="gold">
<form action="process-game.php" method="post" >
YOUR GOLD: <input type="hidden" name="building" value="gold"/>
</form>
</div>
<div class="farm_form">
<h2>Farm</h2>
<form action="process-game.php" method="post" >
<input type="hidden" name="building" value="farm"/>
<input type="submit" value="Find Gold!"/>
</form>
</div>
<div class="farm_form">
<h2>Cave</h2>
<form action="process-game.php" method="post">
<input type="hidden" name="building" value="cave"/>
<input type="submit" value="Find Gold!"/>
</form>
</div>
<div class="farm_form">
<h2>House</h2>
<form action="process-game.php" method="post">
<input type="hidden" name="building" value="house"/>
<input type="submit" value="Find Gold!"/>
</form>
</div>
<div class="farm_form">
<h2>Casino</h2>
<form action="process-game.php" method="post">
<input type="hidden" name="building" value="casino"/>
<input type="submit" value="Find Gold!"/>
</form>
</div>
</div>
Here's my process.php:
<?php
session_start();
if(isset($_POST['building'])){
echo earn_gold();
}
function earn_gold(){
if($_POST['building'] == "farm"){
$gold = rand(10,20);
}else if($_POST['building'] == "cave"){
$gold = rand(5,10);
}else if($_POST['building'] == "house"){
$gold = rand(2,5);
}else if($_POST['building'] == "casino"){
$gold = rand(0,50);
}
return $gold;
}
?>
Any idea how to do this?

I know, you basically wanted a solution in PHP. Still, I could not resist showing you, how easy it would be doing the same in JavaScript/jQuery. Have a look at it or simply ignore it. It is up to you ... ;-)
// define gold amounts for each button (min,max):
var finds={farm:[10,20],cave:[5,10],house:[2,5],casino:[0,50]};
$(function(){
$(':submit').click(function(){ // for all submit buttons: bind the click event to a function ...
var place=$(this).closest('div[id]').attr('id'); // get the id of the buttin's parent div
var fnd=finds[place]; // get the min/max array for the current button
with ($('#gold span')) // locate and use the <span> inside the div with id=gold
text(parseFloat(text()) // get the current value of the span (convert to float)
+fnd[0]+Math.ceil(Math.random()*(fnd[1]-fnd[0]))); // add the gold ...
});
})
div {display:inline-block; width: 120px; border:1px solid grey}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="farm_form" id="gold">
<h2>Your Gold</h2><span>0</span>
</div><br>
<div class="farm_form" id="farm">
<h2>Farm</h2><input type="submit" value="Find Gold!"/>
</div>
<div class="farm_form" id="cave">
<h2>Cave</h2><input type="submit" value="Find Gold!"/>
</div>
<div class="farm_form" id="house">
<h2>House</h2><input type="submit" value="Find Gold!"/>
</div>
<div class="farm_form" id="casino">
<h2>Casino</h2><input type="submit" value="Find Gold!"/>
</div>

If you really need it, I guess you can do it with sessions.
if (isset($_POST['building'])) {
// getting random gold
$earn_gold = earn_gold();
// adding to session called "gold"
$_SESSION['gold'] = (isset($_SESSION['gold']) ? $_SESSION['gold'] + $earn_gold : $earn_gold);
// redirect back to process page
header('Location: process.php');
exit;
}
And then outputting it like so
<div id="gold">
<form method="post" >
YOUR GOLD: <input type="hidden" name="building" value="gold"/>
<?php
// if set, outputting sessions "gold" value
if (isset($_SESSION['gold'])) echo $_SESSION['gold'];
?>
</form>
</div>

When the user click on find gold then submit a form which will add the gold to the total result. For example if the user gets 3 gold then add the gold variable.
$totalGold = 0;
when user.click button then $totalgold +3;

Have one form element and use javascript to assign onclick events to each of the butons and may be use ajax to submit the form dynamically and display the results back on same page.

Related

how to get the submit button value which is in while loop using post method

Input field inside a while condition i'm displaying the tab in which tab values are fetched from table red_digid_info
<form method="POST" action="" id="form_isp_status" onsubmit="submit_isp_status('form_isp_status');"">
<div class="row">
<label for="fromdate" class="col-sm-1 control-label"> FROM DATE </label>
<label for="todate" class="col-sm-1 control-label" style="margin-left: 4cm;"> TO DATE </label>
</div>
<div class="row">
<div class="col-sm-1">
<div class="input-group">
<input type="text" class="form-control" id="fromdatepicker" name="fromdate" placeholder="yyyy-mm-dd" style="width:200px;height:33px;">
<span class="input-group-addon"><i class='glyphicon glyphicon-calendar'></i></span>
</div>
</div>
<div class="col-sm-1" style="margin-left:4cm">
<div class="input-group">
<input type="text" class="form-control" id="todatepicker" name="todate" placeholder="yyyy-mm-dd" style="width:200px;height:33px;">
<span class="input-group-addon"><i class='glyphicon glyphicon-calendar'></i></span>
</div>
</div>
<div class="col-sm-offset-2 col-sm-2">
<input type="submit" value="ISP Status" class='btn btn-purple btn-rounded w-md m-b-5' name="isp_button">
<input type="hidden" value="1" name="pointer">
<button type="button" class="btn btn-pink btn-rounded w-md m-b-5" onclick="resetforms('form_isp_status')">Reset</button>
</div>
</div>
<div class="row">
<label for="isp" class="col-sm-1 control-label"> SELECT ISP</label>
</div><div class="row">
<div class="tab">
<?php
$isp_tab = mysql_query("SELECT DISTINCT(`isp`) FROM `red_dgid_info`");
while ($result = mysql_fetch_array($isp_tab)) {
$isp_value = $result[0];
echo '<input class="tablinks ion-social-rss" type="submit" name="isp_value[]" value="'.$isp_value.'">';
//echo '<input type="hidden" name="isp_hidden_value[]" value="'.$isp_value.'">';
}
?>
</div>
</div></form>
if i click any one value of a tab i ve to display the tab content so i need the value of submit button in php post method
if($_REQUEST['pointer'] ==1)
{
var_dump($_POST);
//-------status criteria given---------------------//
//-----------isp tab submiited--------------//
if(isset($_POST['isp_value']))
{
print_r($_POST['isp_value']);
$isp=$_POST['isp_value'];
}
//------------------end----------------------//
//----------hidden value array--------------//
/*$data = $_POST['isp_hidden_value'];
foreach($data as $isp)
{
echo "isp_hidden =".$isp;
}
//---------------another way----------------//
$isp_hidden = $_POST['isp_hidden_value'][$isp];*/
//--------------end------------------------//
$date= date("Y-m-d");;
$fromdatepicker =$_POST['fromdate'];
$todatepicker =$_POST['todate'];
exit;
}
if(isset($_POST['isp_value'])) //this if condition fails isp_value is not set don't know the reason and solution for it
submit function
function submit_isp_status(formId) {
if($("#"+formId).valid() == true) {
$.ajax({
type: 'POST',
url: 'webxstatus.php', //same page
data: $("#"+formId).serialize(),
success: function(data) {
..........
}
});
}
}
I'm stuck with this for past 2 days anyone help me to solve this.
you need to change your input name to array like this isp_value[] so only you can get the value which submit button you clicked otherwise you will get last value only .
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value[]' value='$isp_value'></input>"
PHP :
print_r($_POST['isp_value']);
And also minor single quotes problem in your isp_hidden_value
echo '<input type="hidden" name="isp_hidden_value[]" value="'.$isp_value.'">';
note:
if you need currently clicked submit button value means . don't use hidden field it will collect all values . just insert the value in submit button it will collect only curently clicked element value only as a array
Try this example :
<?php
if(isset($_POST['xyz']))
{
print_r($_POST);
}
?>
<form action="" method="post">
<input type="submit" name="xyz[]" value="1" >
<input type="submit" name="xyz[]" value="2" >
</form>
<?php $isp_tab=mysql_query("select distinct(isp) from red_dgid_info");
while($result=mysql_fetch_array($isp_tab))
{
echo'<form method="POST" action="" id="form_isp_status" onsubmit="submit_isp_status('form_isp_status');">';
$isp_value =$result[0];
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value' value='$isp_value'></input>";
echo '<input type="hidden" name="isp_hidden_value" value='$isp_value'>';
echo'</form>';
}?>
put form inside while loop
while($result=mysql_fetch_array($isp_tab))
{
$isp_value =$result[0];
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value' value='$isp_value'></input>";
echo '<input type="hidden" name="isp_hidden_value[]" value='$isp_value'>';
}?>
$data =$_POST['isp_hidden_value'];
foreach($data as $isp)
{
echo "isp_hidden"=$isp;
}
Use input field 'isp_hidden_value' as array and fetch values using foreach
You need to do some changes in your code, and after that i hope it will work perfectly:
Change hidden field
from:
echo '<input type="hidden" name="isp_hidden_value" value="$isp_value">';
to:
echo "<input type='hidden' name='isp_hidden_value[$isp_value]' value='" . $isp_value . "'>";
In the post method change value assignment of hidden field
from:
$isp_hidden = $_POST['isp_hidden_value'];
to:
$isp_hidden = $_POST['isp_hidden_value'][$isp];
Rest should work fine.
Logic behind this change is to use array when using same name for multiple input types. Here you are using a flat variable which will hold only one value, which will get assigned at the end. If you use array it will hold multiple values and allows you to get your desired result.
You don't need a hidden field for this. A button with a name should send it's value.
<?php
var_dump($_POST);
?>
<form method="POST" action="">
<div class="row">
<div class="tab">
<input type="submit" name="button" value="test1">
<input type="submit" name="button" value="test2">
</div>
</div> </form>
Will tell me that $_POST['button'] is either test1 or test2
Which means that the following should work
<form method="POST" action="" id="form_isp_status" onsubmit="submit_isp_status('form_isp_status');"">
<div class="row">
<div class="tab">
<?php $isp_tab=mysql_query("select distinct(isp) from red_dgid_info");
while($result=mysql_fetch_array($isp_tab))
{
$isp_value =$result[0];
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value' value='$isp_value'>";
// note: input is a empty tag, meaning that it is not to be closed using </input> but by using />, which
// is only relevant for XHTML
}?>
</div>
</div> </form>
Edit:
On the server side the only thing you have to do is use the value of $_POST['isp_value'].
var_dump($_POST); // only to check the POST variable during debugging
if (isset($_POST['isp_value'])) { // Possibly not needed if there are no other submit buttons in the from, but good practice to check if something exists
// do something using $_POST['isp_value']
}
As a sidenote: mysql_* has been deprecated in PHP 5.5.0 and been removed in PHP 7.0. It is recommended to either use MySQLi or PDO instead

How to stop 2 buttons from opening the same div tag in jquery

I have been working on a comment system in php and jQuery. I am using jQuery to slide a form whenever you press reply but instead 2 buttons work for only one form.
I am using php to get the data from a mysql database and display the content it displays it in div tags with a button that says reply when I click on the second button the first div come's down.
PHP CODE:
<?php if(!isset($_SESSION['fname']) && !isset($_SESSION['username']) && !isset($_SESSION['email'])) {
echo "<h1>You must be logged in to comment</h1>";
} else { ?>
<div id="comment">
<form action="createcomment.php?videoid=<?php echo $_GET['id']; ?>" method="post">
Comment: <br /><textarea name="comment" placeholder="Your comment..."></textarea><br />
<input type="submit" name="submit" value="Post Comment" class="btn btn-warning">
</form>
</div>
<?php } ?>
<div id="comments">
<?php $sql = "SELECT * FROM comments WHERE videoid = " . $_GET['id'];
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_assoc($result)) {
if(!empty($result)) {
?>
<div class="comment">
<h5><?php echo $row['name']; ?></h5>
<p><?php echo $row['comment']; ?></p>
<button class="btn btn-primary btn-small">Reply</button>
<div id="reply">
<form action="replycomment.php?videoid=<?php echo $_GET['id']; ?>&commentid=<?php echo $row['id']; ?>" method="post">
Reply Message: <br /><textarea name="comment" placeholder="Your comment..."></textarea><br />
<input type="submit" name="submit" value="Post Reply" class="btn btn-warning">
</form>
</div>
</div>
<?php }else {
echo "<h1>There are no comments.</h1>";
}
}?>
</div>
jQuery code:
<script>
$(document).ready(function(){
$("#reply").hide();
$("#comments > div > button").click(function(){
$("#reply").slideToggle();
});
});
</script>
The jQuery is supposed to hide all of the reply divs and when you click reply the div opens instead the first button works but the last button opens the first one i have no idea what is going on.
Thank you.
There can only be one of each ID in the entire DOM. You have an element with the id of "reply". Since the database is looping through all of the comments, there will be multiple elements with the id of "reply". This syntax is not correct.
Now, if you click on a button to toggle the element with the id of "reply", all of them will toggle. That's not what you want. Change the HTML to:
<button class="btn btn-primary btn-small">Reply</button>
<div class="reply">
<form action="replycomment.php?videoid=<?php echo $_GET['id']; ?>&commentid=<?php echo $row['id']; ?>" method="post">
Reply Message: <br /><textarea name="comment" placeholder="Your comment..."></textarea><br />
<input type="submit" name="submit" value="Post Reply" class="btn btn-warning">
</form>
</div>
Note that I have removed the id, and added the class. There can be multiple classes in a DOM. And so, the jQuery needs to hide all of the classes, so:
$(document).ready(function(){
$(".reply").hide();
// Hides all the elements with class="reply"
});
Now all we need is the button click action. If we just change the hashtag to the dot and make it a class, it still will toggle ALL of the elements with the class of reply. We need to just toggle the element that is right after the clicked button... right?
And so:
$(document).ready(function(){
$("#comments > div > button").click(function(){
$(this).nextAll('.reply:first').slideToggle();
// Gets all the next sibling elements under the same parent, and selects the first one with the class="reply"
});
});

Save checked values on page refresh?

Ive saved form data with ajax and php, reusing the data from the database.
However the way I am approaching this is different, there is no database, so some insight would be great.
I am emailing form data, all the data is just simple checkboxes, the values are either 0 or 1. When the user refreshes the page id like to keep the checked values.
I guess without a database I would need to use cookies, and the only way to avoid cookies would be ajax and a database (strictly my logic, not sure if true), this is why I am asking, I just want a simple solution.
Form snippet:
<input name="sharks" type="hidden" value="0">
<input name="sharks" type="checkbox" value="1" id="sharks" '.$VALUE ? ' checked="checked"' : ''.'>
The php part of that input is shaky, Id like to question whether the value is 0 or 1, if its 1 then its checked if its 0 then empty.
Getting it from the database would be easier but not so sure since there is no database, Im guessing cookies would come into place.
Sorry if this last part is shaky but im a little unsure and dont know where to look.
Using Sessions:
session_start();
if(isset($_POST['submit'])) {
if(isset($_POST['personalization_result'])) {
$_SESSION['value'] = $_POST['personalization_result']; }
else {
$_SESSION['value'] = '';
}
}
Form
<form action="<?php the_permalink(); ?>" method="post" id="question-form">
<input type="hidden" name="submit" value="1">
<?php
if ($_SESSION['value'] == 1) {
$checked = 'checked="checked"'; }
?>
<li>
<input name="personalization_result[memory_0]" type="hidden" value="0">
<input name="personalization_result[memory_0]" type="checkbox" value="1" id="personalization_result_memory_0" <?php $checked ?> >
</li>
<li>
<input name="personalization_result[memory_1]" type="hidden" value="0">
<input name="personalization_result[memory_1]" type="checkbox" value="1" id="personalization_result_memory_1" <?php $checked ?> >
</li>
<li>
<input name="personalization_result[memory_2]" type="hidden" value="0">
<input name="personalization_result[memory_2]" type="checkbox" value="1" id="personalization_result_memory_2" <?php $checked ?> >
</li>
This code stores the data in a session:
<?php
session_start();
if(isset($_POST['submit']))
{
if(isset($_POST['sharks']))
{
$_SESSION['value'] = $_POST['sharks'];
}
else
{
$_SESSION['value'] = '';
}
}
?>
<form action="" method="POST">
<?php
print '<input name="sharks" type="checkbox" value="1" id="sharks" ';
if ($_SESSION['value'] == 1)
{
print ' checked="checked"';
}
print ">";
?>
<br>
<input type="submit" name="submit" value="Save" />
</form>
Worked for me, keeping the checkbox checked after I closed and opened the browser again. After some testing I added a rather complex if to avoid the undefined variable notice. Now the set part seems robust.
You can either use session or cookie. Basically you will access using $_COOKIE or $_SESSION. I would rather say that this is easier than using a database.
For cookies have a look at setcookie (http://www.php.net/setcookie)
For sessions: http://php.net/manual/en/book.session.php
I would use local storage or session storage, this is a client side memory storage location that persists even if the page is refreshed, it is integrated into html5.
Here is a nice tutorial about it:
http://www.w3schools.com/html/html5_webstorage.asp
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Persist checkboxes 1</title>
<script>
window.jQuery || document.write("<script src='jquery-.1.1.js'><\/script>");
</script>
<script>
$(document).ready(function()
{
$('#me').click(function()
{
var seloption = $('input[type="checkbox"]:checked');
if (seloption.length > 0)
{
var abc = seloption.length + "checked \n";
//alert(abc);
i = 0;
seloption.each(function()
{
abc = abc + $(this).text(seloption[i]) + "<br>";
}
);
$('#msg').html(abc);
}
}
);
}
);
</script>
</head>
<body>
<div>
<label for="option1">Option 1</label>
<input type="checkbox" id="option1">
</div>
<div>
<label for="option2">Option 2</label>
<input type="checkbox" id="option2">
</div>
<div>
<label for="option3">Option 3</label>
<input type="checkbox" id="option3">
</div>
<div>
<label for="option4">Option 4</label>
<input type="checkbox" id="option4">
</div>
<div>
<label for="option5">Option 5</label>
<input type="checkbox" id="option5">
</div>
<div>
<label for="option6">Option 6</label>
<input type="checkbox" id="option6">
</div>
<div>
<label for="option7">Option 7</label>
<input type="checkbox" id="option7">
</div>
<div>
<label for="option8">Option 8</label>
<input type="checkbox" id="option8">
</div>
<div>
<label for="option9">Option 9</label>
<input type="checkbox" id="option9">
</div>
<button type="button" id="me">Submit</button>
<div id="msg">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/jquery.cookie/1.4.0/jquery.cookie.min.js"></script>
<script>
$(":checkbox").on("change", function() {
var checkboxValues = {};
$(":checkbox").each(function() {
checkboxValues[this.id] = this.checked;
});
$.cookie('checkboxValues', checkboxValues, {expires: 1, path: '/'});
});
function repopulateCheckboxes() {
var checkboxValues = $.cookie('checkboxValues');
if (checkboxValues) {
Object.keys(checkboxValues).forEach(function(element) {
var checked = checkboxValues[element];
$("#" + element).prop('checked', checked);
});
}
}
$.cookie.json = true;
repopulateCheckboxes();
</script>
</body>
</html>

Multiple Submit buttons, how do determine which one was clicked?

I have a form with multiple submit buttons.
Each submit button is an IMG SRC trash can which denotes the delete icon for messages in a web based messaging mail inbox
what is the best way to figure out which submit button icon was clicked so that I can then write the PHP/MySQL code to DELETE the message?
if(!empty($_POST)){
// How do I figure out which submit button has been clicked to get the ID of the message to delete?
}
<form method="POST">
<input src="http://www.foo.com/img.png" id="button_1">
<input src="http://www.foo.com/img.png" id="button_2">
<input src="http://www.foo.com/img.png" id="button_3">
<input src="http://www.foo.com/img.png" id="button_4">
...
<input src="http://www.foo.com/img.png" id="button_100">
</form>
Set value for each submit button and check that in php and find which one is clicked
<form method="POST">
<img src="http://www.foo.com/img.png" id="button_1" name="submit_btn" value="1">
<img src="http://www.foo.com/img.png" id="button_2" name="submit_btn" value="2">
<img src="http://www.foo.com/img.png" id="button_3" name="submit_btn" value="3">
<img src="http://www.foo.com/img.png" id="button_4" name="submit_btn" value="4">
...
<img src="http://www.foo.com/img.png" id="button_100" name="submit_btn" value="100">
</form>
echo $_POST['submit_btn']; will give you the value of which submit button is clicked
Give each button a name=""
Then you can do something like
isset($_POST['button_name']) {
// execute code here if true
}
THE solution of this problem is to use the NAME attribute of the tag input/button.
<input type="submit" name="submitSave" value="Save"/>
<input type="submit" name="submitAddComment" value="Add comment"/>
or
<button type="submit" name="submitSave">Save</button>
<button type="submit" name="submitAddComment">Add comment</button>
I think you can also use the value attribute of button tag, this is definitively not possible with input tag.
If you need to use an ID or another variable, use name="submitDelete[888]"
Then, check it with PHP:
if( isset($_POST['submitDelete']) ) {
echo key($_POST['submitDelete']);// Displays the ID to delete, e.g. 888.
}
So many years later, I like button because it allows to display a text or an image independently of the value returned.
Here is an illustration of possibilities which fits the title of this post and more cases than the OP.
<?php
if(!empty($_POST['id'])){
echo 'button '. $_POST['id'] .' clicked';
} elseif ('create' === ($_POST['action'] ?? '')) {
echo 'create clicked'; // ?action=create
} elseif (isset($_POST['action'])) {
echo 'refresh clicked'; // ?action
} elseif (isset($_POST)) {
echo 'Default clicked'; // ?
}
?>
<form method="POST">
<!-- Original Post examples -->
<button type="submit" name="id" value="1"><img src="http://www.foo.com/img.png"></button>
<button type="submit" name="id" value="2"><img src="http://www.foo.com/img.png"></button>
...
<button type="submit" name="id" value="100"><img src="http://www.foo.com/img.png"></button>
<!-- Additional possibilities -->
<!-- ?action=create -->
<button type="submit" name="action" value="create">New element</button>
<!-- ?action -->
<button type="submit" name="action">Refresh</button>
<!-- ? -->
<button type="submit">Default</button>
</form>
you can give a name and a value to each of your buttons. It will then show up under $_POST['submit']
<img src="http://www.foo.com/img.png" id="button_4" name='submit' value='4' />
You have to pass your value to the current file by declearing name and value for each.. then you can echo in your php script in order to know which one is clicked.

How to set two buttons on one form html&php

This form should calculate numbers and save
Now there are two buttons One is call Calculator and two call Save
If I press Calculator
I get the form action is going to file name save.php And I do not want it that way
How can I set it up that button do something else
Example
Calculator = Calculator
Save = save.php
Is it possible to set it
Because it is one form
Thanks to anyone who can help
<?php
error_reporting (0);
$NUM = $_POST["NUM"];
$NUM2 = $_POST["NUM2"];
$NUM = "$NUM";
$NUM2 = "$NUM2";
$subtotal= $NUM+$NUM2;
?>
<form action="save.php" method="POST" name="Calculator">
<p>
<input name="NUM" type="text" value="<?php echo $_POST["NUM"]; ?>" />
</p>
<p>+</p>
<p>
<input name="NUM2" type="text" value="<?php echo $_POST["NUM2"]; ?>" />
</p>
<p>
<input name="subtotal" type="text" value="<?php echo "$subtotal";?>" />
</p>
<p>
<input name="submit" type="submit" value="Calculator" />
<p>
<input name="submit" type="submit" value="Save" />
</p>
</form>
You can have all the logic in a single PHP script (no need to direct to a different script depending on the button). If the logic is complicated, use include statements in order to separate the code.
Name the buttons differently:
<input name="calculator_submit" type="submit" value="Calculator" />
<input name="save_submit" type="submit" value="Save" />
Then in PHP:
if (isset($_GET['calculator_submit'])) {
// ...
} else if (isset($_GET['save_submit'])) {
// ...
} else {
// ...
}
If you really need different PHP script, then you'll have to go with Javascript (function will change the form action when a submit is clicked).
Since you are now using two submit buttons, both will submit the form and go to save.php.
Make your "calculator" button an input type=button instead of submit, and handle it via JavaScript.
Just FYI:
HTML5 allows to define a different form target URL by specifying the formaction attribut on a submit button – but browser support is lousy as of now.
Form and Buttons
<input name="submit" type="button" onclick="submitForm('Calculator')" value="Calculator" />
<input name="submit" type="button" onclick="submitForm('Save.php')" value="Save" />
Some jquery:
function submitForm(path) {
$('#Calculator').attr('action', path);
$('#Calculator').submit();
}

Categories