PHP 使用默认值计算表单值的脚本可能在提交时使用 if 和 else 语句。至 page2.php

PHP Script to Calculate Form Values with default values maybe using if and else statements on submit. to page2.php

j_s_stack 的更新我已经在此处添加了大部分代码,以便您查看脚本所做的计算,正如您从评论选项卡中了解到的那样,我对 php 进行了一些更改脚本和论坛脚本,相应地更改 id,

            <div class="action-form-field">
              <label class="frm">*Property Type</label>
              <select name="fldPropertyType" id="fldPropertyType" title="Property_Type" class="details-form-action select-details">
                <option value="5" selected>Terraced</option>
                <option value="10">Semi-Detached</option>
                <option value="10">Detached</option>
                <option value="10">Bungalow</option>
                <option value="5">Flat/Apartment</option>
                <option value="10">Other</option>
              </select>
            </div>
            <div class="action-form-field">
              <label class="frm">*Approx Property Value</label>
              <select name="fldAPV" title="Approx_Property_Value" id="fldAPV" class="details-form-action select-details">
              <option value="100" selected="selected">Select value</option>
              <option value="100">£0 - £100,000</option>
              <option value="200">£100,001 - £200,000</option>
              <option value="300">£200,001 - £300,000</option>
              <option value="400">£300,001 - £400,000</option>
              <option value="500">£400,001 - £500,000</option>
              <option value="600">£500,001 - £600,000</option>
              <option value="700">£600,001 - £700,000</option>
              <option value="800">£700,001 - £800,000</option>
              <option value="900">£800,001 - £900,000</option>
              <option value="1000">£900,001 - £1,000,000</option>
              <option value="1150">£1,000,001 - £2,000,000</option>
              <option value="1350">£2,000,001 - £5,000,000</option>
              <option value="1500">£5,000,001 and above</option>
              </select>
          </div>
            <div class="action-form-field">
              <label class="frm">*Number of Bedrooms</label>
              <select name="fldNOBEDS" title="Number_Of_Bedrooms" id="fldNOBEDS" class="details-form-action select-details">
                <option value="15" selected="selected">I'm Not Sure</option>
                <option value="5">1 Bedroom</option>
                <option value="10">2 Bedrooms</option>
                <option value="15">3 Bedrooms</option>
                <option value="20">4 Bedrooms</option>
                <option value="25">5 Bedrooms</option>
                <option value="30">6 Bedrooms</option>
                <option value="35">7 Bedrooms</option>
                <option value="50">8 Bedrooms +</option>
              </select>
            </div>
          <div class="action-form-field">
              <label class="frm">*Select Survey Required</label>
              <select name="fldST" title="Survey_Type" id="fldST" class="details-form-action select-details">
                <option value="not-sure" selected="selected">I'm Not Sure</option>
                <option value="15">RICS Condition Survey</option>
                <option value="25">RICS Homebuyer Survey</option>
                <option value="50">RICS Building Survey</option>
              </select>
            </div>
        </div>
 <input type="submit" name="submit" value="GET YOUR INSTANT QUOTE" class="cash-btn">

PHP脚本

 <?php 

    function calculate(){
        $calculate = $_POST['fldNOBEDS'] + $_POST['fldAPV'] + $_POST['fldPropertyType']; //... 
        return $calculate;
    }

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

选择应显示的值时的示例:

  <option value="5" selected>Terraced</option>
  <option value="100">£0 - £100,000</option>
  <option value="5">1 Bedroom</option>
  <option value="15">RICS Condition Survey</option>

总数应该是:您的报价:125(正确)

当我 select "not-sure" 作为我的调查类型时,答案是:

condition Quote: 65
homebuyer Quote: 235
building Quote: 260
valuation Quote: 160 

<<<<---------------- 最后一节的更新---------------->> >>>>

        <!-- action block1 -->
        </form>
        <form name="form2" id="form2" method="post" action="">
        <input type="hidden" name="Name" id="Name" value="" />
        <input type="hidden" name="Email" id="Email" value="" />
        <input type="hidden" name="Phone" id="Phone" value="" />
        <input type="hidden" name="Postcode" id="Postcode" value="" />
        <!-- action block2 -->
        <div class="inner_actionblock2">
            <div class="inner_actionblock_top">
                <p class="cash_head">Assisted Sale</p>
            </div>
            <div class="inner_actionblock_mid">
                <div class="actiobox_shade-new"></div>
                <div class="inr_action_list">
                    <ul>
                        <li>.... Text about Surveys......</li>
                        <li>.... Text about Surveys......</li>
                        <li>.... Text about Surveys......</li>
                        <li>.... Text about Surveys......</li>
                </div>
                <div class="ur_offer">Your Condition Survey Quote is:</div>
                <div class="box_center">
                    <div class="action_txt_fld">
                        <span><img src="sign2.png" alt="" /></span>
                        <div class="action_txt_fldbox">
                            <input type="text" name="pricetxt" class="price_txt" readonly value="<?php echo $quote?>"/>
                        </div>
                    </div>
                    <p class="last_boxtext">Please Confirm Contact Number:</p>
                    <p class="inputbox"><input type="text" name="pnumber" id="pnumber" value="" class="tbox"></p>
                </div>
                <div class="action_cash1"><input type="submit" id="button3" class="action_cash1_submit" name="submit" value="Buy Now" /></div>
            </div>
            <div class="inner_block"></div>
        </div>
        <!-- block2 -->
        </form>

我已经添加了列出调查报告报价的每个框的代码,正如您在值中看到的那样我有之前的“”,所以我想我可以尝试使用 h1 - h5 标签和看看什么最适合?

谢谢。

我会将所有计算内容放在一个函数中。然后创建另一个 IF 条件以查看用户选择的内容:

<?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.
    }
    ?> 

我没有再次测试过,所以他们可能有一些错误。