如何使用if语句更改表单中的输入值?

时间:2016-03-30 12:03:17

标签: php

我已经制作了一个我想要的计算器, value="$sm8totalD"依赖于此if语句,

if ($sm8jobs <= "20" ) { echo "0"; }  else  {echo $sm8total;}

我可以在表单中找到if语句但是我不确定如何在表单中连接它?任何帮助表示赞赏,代码如下。 链接:http://www.vestedutility.com.au/ec/inc/calculator.php#

<?php
if (isset($_POST['sm8charge'])) $sm8charge= $_POST['sm8charge'];
if (isset($_POST['sm8jobs'])) $sm8jobs = $_POST['sm8jobs'];
if (isset($_POST['vrrate'])) $vrrate = $_POST['vrrate'];
if (isset($_POST['vrhours'])) $vrhours = $_POST['vrhours'];
if (isset($_POST['vurate'])) $vurate= $_POST['vurate'];
if (isset($_POST['vujobs'])) $vujobs= $_POST['vujobs'];
if (isset($_POST['bkrate'])) $bkrate= $_POST['bkrate'];
if (isset($_POST['bkhours'])) $bkhours= $_POST['bkhours'];


$sm8total = $sm8charge * ($sm8jobs - 20);
$vrtotal = $vrrate * $vrhours;
$vutotal = $vurate * ($vujobs - 2);
$bktotal= $bkrate * $bkhours;
$tmc= $sm8total + $vrtotal + $vutotal + $bktotal;
$sm8totalD="$ ".number_format($sm8total, 2);
$vrtotalD="$ ".number_format($vrtotal, 2);
$vutotalD="$ ".number_format($vutotal, 2);
$bktotalD="$ ".number_format($bktotal, 2);
$tmcD="$ ".number_format($tmc, 2);

if ($sm8jobs <= "20" ) { echo "0"; }  else  {echo $sm8total;}


echo <<<_END



<body oninput="Javascript: document.vu.submit();">
<form id="ve" name="vu" method='post' action='#'>

<table border='0' width='500px' cellpadding='3' cellspacing='1' class="table">

    <tr class="calcheading">
        <td class="priceHeading" colspan="4"><strong>Pricing Calculator</strong></td>
    </tr>
    <tr class="calcrow">
        <td class="heading"><a class="buttonheading" href="http://www.vestedutility.com.au/ec/servicem8.php" class="heading"><div class="bheading">Job Management ServiceM8</div></a></td>
        <td class="price" align="center">

                <b>Price per job:</b>


            <input class="fixed" type='text'  name='sm8charge' value="0.50"/>
            50c

        </td>
        <td class="infoTask">
            <b>Number of jobs processed. The first 20 jobs are free.</b>
        </td>
        <td class="invalue" align="center">
            <input class="input" type='text' name='sm8jobs' value="$sm8jobs" placeholder="50"/>
        </td>

        <td  align="center">
            <input class="total" type="text" value="$sm8totalD">
if ($sm8jobs <= "20" ) { echo "0"; }  else  {echo $sm8total;}
                </td>
        <td class="signup"><a class="buttonsignup" href="http://www.vestedutility.com.au/ec/index.php" class="heading"><div class="bsignup">Sign me up</div></a></td>

    <tr class="calcrow">
        <td class="heading">
            <a class="buttonheading" href="http://www.vestedutility.com.au/ec/reception.php" class="heading"><div class="bheading">Virtual Reception</div></a></td>
        <td class="price" align="center">
            <b>Hourly Rate:</b>
            <input class="fixedpr" type='text' name='vrrate' value="49.50"/>$49.50
        </td>
        <td class="infoTask">
                Number of hours, incoming calls are calculated in 5 minute increments.
        </td>
        <td class="invalue" align="center">
            <input class="input" type='text' name='vrhours' value="$vrhours" placeholder="10"/>
        </td>

        <td align="center">
            <input  class="total" type="text" value="$vrtotalD"></td>
        <td class="signup"><a class="buttonsignup" href="http://www.vestedutility.com.au/ec/index.php" class="heading"><div class="bsignup">Sign me up</div></a></td>   

    <tr class="calcrow">
        <td class="heading">
            <a class="buttonheading" href="http://www.vestedutility.com.au/ec/marketing.php" class="heading"><div class="bheading">Vested Utility Job Leads</div></a></td>

        <td class="price" align="center">
            <b>Price per job lead:</b>
            <input class="fixedpr" type='text' name='vurate' value="20.00"/>$20.00
        </td>
        <td class="infoTask">
                Number of job leads. The first 2 jobs per month are free.
        </td>
        <td class="invalue" align="center">
            <input class="input" type='text' name='vujobs' value="$vujobs" placeholder="4"/>
        </td>

        <td class="price"  align="center">
            <input class="total" type="text" value="$vutotalD"></td>
        <td class="signup"><a class="buttonsignup" href="http://www.vestedutility.com.au/ec/index.php" class="heading"><div class="bsignup">Sign me up</div></a></td>

    <tr class="calcrow">
        <td class="heading">
            <a class="buttonheading" href="http://www.vestedutility.com.au/ec/bookkeeping.php" class="heading"><div class="bheading">Accounts - Bookkeeping</div></a></td>
        <td class="price"  align="center">
            <b>Hourly Rate:</b>
            <input class="fixedpr" type='text' name='bkrate' value="49.50"/>$49.50
        </td>
        <td class="infoTask">
                Number of hours.
        </td>
        <td class="invalue" align="center">
            <input class="input" type='text' name='bkhours' value="$bkhours" placeholder="5"/>
        </td>

        <td align="center">
            <input  class="total"  type="text" value="$bktotalD"></td>
        <td class="signup"><a class="buttonsignup" href="http://www.vestedutility.com.au/ec/index.php" class="heading"><div class="bsignup">Sign me up</div></a></td>       
    <tr class="calcrow tmc">
    </tr>
    <tr class="calcrow tmc">
        <td class="extra" colspan="2]"></td>
        <td class="tmc" colspan="2">
            <strong class="header">Total Monthly Cost</strong>

            All prices are calcualted on a monthly basis and GST is not charged.
        </td>

    <td class="tmcD " align="center"><input class="total" type="text" value="$tmcD"></td>




    <tr class="submit">
        <td colspan="2">
        <input type='submit' value='Calculate'/>
        </td>
    </tr>
_END;
?>




</table>
</form>
</body>

1 个答案:

答案 0 :(得分:0)

似乎你使用了heredoc,并且在heredoc中的if语句是不可能的,所以你需要在@ echo @之前为if语句的结果定义新的变量并在右边打印它

...
if ($sm8jobs <= "20" ) { $output = 0; }  else  {$output = $sm8total;}

echo <<<_END
...
$output
...
_END;