Forum Moderators: coopster
I'm creating a form for a website and I need to have a calculation performed on one of the form inputs (a numerical value).
Basically, the user will enter a value into the field (x) in the form, and submit it as usual. This information will then all be processed and emailed to the site owner, and take the user to a second page which will say "Please wait... Calculating your value" or something similar. It'll then go to a third page which will display a value based on a calculation (x * 0.82) and ask the user to confirm the offer.
To give you a better idea of the process, <snip> is pretty much the sort of thing we're looking at.
Is anyone able to help or point me in the right direction?
[edited by: dreamcatcher at 12:44 pm (utc) on Mar. 10, 2008]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]
Say if your input box has the 'name' attribute of 'input', get the form to submit to say confirm.php with the method of 'POST'.
Eg:
<form action="confirm.php" method="post">
<input name="input" type="text" />
</form>
The code on confirm.php could contain something like
<?PHP
//Your calculation
$value = $_POST['input'] * 0.82;
//Output result
echo $value;
?>
This is obviously very simplified but should do what you want it to.
Also, the calculating page is used to give the impression that it's searching through a database of similar properties and doing a lot of calculations - it's all faff, but what the client wants... :-)
form.php -
<form action="confirm.php" method="post">
<input name="input" type="text" />
</form>
confirm.php -
<body onload="document.valform.submit();">
<form name="valform" action="complete.php" method="post">
<input name="input" type="hidden" value="<? echo $_POST['value']; ?>"/>
</form>
Please wait... Calculating your value
</body>
complete.php
<?PHP
//Your calculation
$value = $_POST['input'] * 0.82;
//Output result
echo $value;
?>
For the second file look for a javascript function to submit after a certain number of seconds otherwise it will just submit as soon as it loads but usually displays the text for a split second.
Just set the field type to 'Hidden'.
Say if your input box is like this:
<input name="input1" type="hidden" />
To display this in the php file you've posted the form to just type:
<?php echo $_POST['input1']; ?>
You can then obviously assign this to a variable or whatever you wnat to do with it.