Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP form & calculations

    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?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,467
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    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... :-)

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,467
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    A really simple example of passing using POST method and hidden form variables:

    The first form:
    PHP Code:
    <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 Code:
    <?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 Code:
    <?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.

  • #5
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by mlseim View Post
    =================

    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?,

    PHP Code:
    $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,

    Edit:
    Changelog:
    1.0.0 - fix some bug and improve functionality

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


    best regards
    Last edited by oesxyl; 03-11-2008 at 02:06 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •