lucerias Posted November 2, 2006 Share Posted November 2, 2006 I am currently create a calculator and then completed the HTML form interface with fields and labels but now i have no idea how to click on the calculate button and then it will call PHP to do the calculation and then pass back the value and display on the html form field? Please provide a simple code sample. Thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/25878-html-form-with-php/ Share on other sites More sharing options...
lucerias Posted November 2, 2006 Author Share Posted November 2, 2006 May i know the meaning of action of form? Quote Link to comment https://forums.phpfreaks.com/topic/25878-html-form-with-php/#findComment-118213 Share on other sites More sharing options...
fert Posted November 2, 2006 Share Posted November 2, 2006 action refers the user to the script that will handle the form data. example:[code]<form method="post" action="script.php">[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25878-html-form-with-php/#findComment-118225 Share on other sites More sharing options...
Skatecrazy1 Posted November 2, 2006 Share Posted November 2, 2006 this has been tested and works:[code] <?php $self = $_SERVER['PHP_SELF']; $operator = $_POST['radio']; $value1 = $_POST['value1']; $value2 = $_POST['value2']; if(isset($operator)){ if($operator == "*"){ $final_value = $value1 * $value2; } elseif($operator == "/"){ $final_value = $value1 / $value2; } elseif($operator == "+"){ $final_value = $value1 + $value2; } elseif($operator == "-"){ $final_value = $value1 - $value2; } } else { $final_value = ""; }?><form method="post" action="<?php echo $self; ?>">First Value <input type="text" name="value1" /><br />+ <input type="radio" name="radio" value="+" /> - <input type="radio" name="radio" value="-" /> x <input type="radio" name="radio" value="*" /> / <input type="radio" name="radio" value="/" /><br />Second Value <input type="text" name="value2" /><br /><input type="submit" value="Calculate" /><br /><br />Final Value: <input type="text" value="<?php echo $final_value; ?>" /></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25878-html-form-with-php/#findComment-118229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.