...

View Full Version : PHP form & calculations



AdamC86
03-10-2008, 01:47 PM
Hi all,

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, http://www.networkpropertybuyers.co.uk/?action=enquiry is pretty much the sort of thing we're looking at.

Is anyone able to help or point me in the right direction?

mlseim
03-10-2008, 02:13 PM
What is the purpose of the "please wait" page ...
the calculation is instant and no waiting is required.

You can pass variables from one form to another using <input type="hidden" ... >
or you can use PHP session variables, or cookies.

AdamC86
03-10-2008, 03:19 PM
What is the purpose of the "please wait" page ...
the calculation is instant and no waiting is required.

You can pass variables from one form to another using <input type="hidden" ... >
or you can use PHP session variables, or cookies.

Thanks for your reply. My knowledge of PHP and variables is pretty stunted - could you expand on your example please?

Also, the please wait 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... :-)

mlseim
03-10-2008, 09:03 PM
A really simple example of passing using POST method and hidden form variables:

The first form:


<form action="secondform.php" method="post">
Name: <input type="text" name="user" value=""><br>
Email: <input type="text" name="email" value=""><br>
<input type="submit" name="submit" value="submit">


secondform.php


<?php
$name=$_POST['name'];
$email=$_POST['email'];
?>

<form action="thirdform.php" method="post">
<input type="hidden" name="user" value="<?=$name?>"><br>
<input type="hidden" name="email" value="<?=$email?>"><br>
Phone: <input type="text" name="phone" value=""><br>
Option: <input type="text" name="option" value=""><br>
<input type="submit" name="submit" value="submit">


thirdform.php


<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$option=$_POST['option'];

Echo"
Here are your results:
$name
$email
$phone
$option
";
?>


=================

The "Wait" page .... <sigh>
Tell your client that nobody will be impressed with that.

Maybe you can do a javascript thing with an animated .gif?

=================

The other option with using Sessions or Cookies ... takes too much time to explain.
Search Google for a "PHP Cookie shopping cart script" ... it's sort of the same thing.

Andrew Johnson
03-10-2008, 09:11 PM
Why use PHP at all? Why not just use Javascript and if you need to change the page (which I doubt) just use AJAX/DHTML

oesxyl
03-11-2008, 02:48 AM
=================

The "Wait" page .... <sigh>
Tell your client that nobody will be impressed with that.

Maybe you can do a javascript thing with an animated .gif?

=================


why not php?, :)



$message = array("please wait, we work hard here...",
"...we are allready finish...",
"...we are closer...",
"sorry, we fail, but don\'t warry, nothing can stop us, will start again...");

if(isset($_GET['msg'])){
$msg = $_GET['msg'];
if($msg < 3){
$msg++;
}else{
$msg = 0;
}
}else{
$msg = 0;
}
print "<p>".$message[$msg]."</p>";
print '<a href="$_SERVER['PHP_SELF']?msg=$msg">click here next week</s>";


not tested, probably don't work, :)


Changelog:
1.0.0 - fix some bug and improve functionality

Todo:
- to add a "you are ugly" message


best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum