我正在構建一個計算器,我差不多完成了。在我的表單上,我在頂部有一個2單選按鈕,用於S.A.E單位或公制單位。PHP在表單上提交後如何保持按鈕正確檢查
當我點擊計算一切運行在計算器工作,但我檢查的單選按鈕回到沒有選中。如果有人點擊指標並點擊提交,我如何在結果之後檢查公制單選按鈕,SAE也一樣?
這裏是我的全部代碼:
<?php
if (isset($_POST['units'])) $units = $_POST['units'];
if (isset($_POST['dia'])) $dia = $_POST['dia'];
if (isset($_POST['wt'])) $wt = $_POST['wt'];
if (isset($_POST['L'])) $L = $_POST['L'];
if (isset($_POST['num'])) $num = $_POST['num'];
if (isset($_POST['waste'])) $waste = $_POST['waste'];
if (isset($_POST['surface'])) $surface = $_POST['surface'];
$denom = ($units == "US" ? 12 : 100);
$coverage = ($units == "US" ? 1000 : 92.9);
//$measurements = ($units == "US" ? "in" : "cm");
$measurements == $units;
if($units == 'US')
$measurements = 'in';
else if($units == 'Metric')
$measurements = 'cm';
else
$measurements = 'in or cm';
$length == $units;
if($units == 'US')
$length = 'feet';
else if($units == 'Metric')
$length = 'meters';
else
$length = 'feet or meters';
$answer1 = pi() * ($dia/$denom) * $L * $num * ($waste + 1)/$coverage;
$answer2 = pi() * (($dia + ($wt * 2))/$denom) * $L * $num * ($waste + 1)/$coverage;
//$answer = ($answer1 + $answer2);
$answer = ($answer);
if($surface == TRUE)
$answer = ($surface * ($waste + 1)/$coverage);
else
$answer = ($answer1 + $answer2);
echo <<<_END
<form method='post' action=''>
<table border='0' width='500px' cellpadding='2' cellspacing='1' class="table">
<tr class="calcheading"><td><label><input type="radio" name="units" value="US" />S.A.E. </label>
<label><input type="radio" name="units" value="Metric" />Metric</label> </td></tr>
<tr class="calcheading"><td colspan="2"><strong>ConBlock MIC Circular Surface Area</strong></td></tr>
<tr class="calcrow"><td>Surface Area ($length):</td><td align="center"><input type='text' name='surface' value="$surface"/></td></tr>
<tr class="calcrow"><td>Diameter ($measurements):</td><td align="center"><input type='text' name='dia' value="$dia"/></td></tr>
<tr class="calcrow2"><td>Wall Thickness ($measurements):</td><td align="center"><input type='text' name='wt' value="$wt"/></td></tr>
<tr class="calcrow"><td>Section Length ($length):</td><td align="center"><input type='text' name='L' value="$L"/></td></tr>
<tr class="calcrow"><td>Number of Sections:</td><td align="center"><input type='text' name='num' value="$num"/></td></tr>
<tr class="calcrow"><td>Waste Variance % (Please add in decimal form):</td><td align="center"><input type='text' name='waste' value="$waste"/></td></tr>
<tr class="submit"><td colspan="2"><input type='submit' value='Calculate'/></td></tr>
_END;
?>
<tr class="calcrow">
<td><i>Gallons Needed for Interior Coating:</td>
<td align="center"><input type="text" value="<?php echo round($answer1, 2)?>"></td></i>
</tr>
<tr class="calcrow">
<td><i>Gallons Needed for Exteror Coating:</td>
<td align="center"><input type="text" value="<?php echo round($answer2, 2)?>"></td></i>
</tr>
<tr class="calcrow">
<td><i>Total Gallons of ConBlock MIC needed:</td>
<td align="center"><input type="text" value="<?php echo round($answer, 2)?>"></td></i>
</tr>
</table>
</form>
我已經找遍了一個答案,但我想我不太清楚,甚至在這件事上搜索。要明白我的意思這裏是網址:
http://www.launchrun.com/consealtest/ConBlockMIC-circular.php
由於任何人誰可以幫我擺脫對這個問題的一些光!
請考慮修復你的編碼風格,因爲你的代碼是一團糟。 –