Skip to content Skip to sidebar Skip to footer

PHP Script To Calculate Form Values With Default Values Maybe Using If And Else Statements On Submit. To Page2.php

update for j_s_stack i have added most of the code here for you to see the calculations the script makes, as you know from the comment tab i have made a few changes to the php scri

Solution 1:

I would put all the caluclation stuff in a function. And then Make another IF Condition to see what the user has choosen:

<?php 

    function calulate(){
        $calc = $_POST['fldAgeOfProp'] + $_POST['fldAPV']; //... 
        Switch ($_POST['fldPropertyType']){                 
                    case 'Semi': 
                       $calc  = $calc + 60;
                    case 'Terraced': 
                       $calc  = $calc + 40;
                    //... For all cases
        }
        return $calc;
    }

    If(isset($_POST['submit'])){
        if($_POST['fldST'] == 'not-sure'){
           $quote =  calculate();
           $quote1 =  $quote + 45;
           echo 'condition Quote: '.$quote1;
           $quote2 =  $quote + 125;
           echo 'homebuyer Quote: '.$quote2;
           $quote3 =  $quote + 150;
           echo 'building Quote: '.$quote3;
           $quote4 = $quote + 50;
           echo 'valuation Quote: '.$quote4;
        }
       else{
           $quote =  calculate() + $_POST['fldST'];
           echo 'Your Quote: '.$quote;
       }               
    }
    else{
      //ERROR Page was accessed without filling the form in.
    }
    ?> 

I haven't tested it again so their might be some mistakes in it.


Post a Comment for "PHP Script To Calculate Form Values With Default Values Maybe Using If And Else Statements On Submit. To Page2.php"