PHP after submit on a form how to I keep the button appropriate checked -
i building calculator , done. on form have 2 radio buttons on top either s.a.e units or metric units.
when click calculate works inn calculator radio button check goes being unchecked. if clicks on metric , clicks submit how keep metric radio button checked after results, same sae?
here whole code:
<?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 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 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>
i have searched on answer guess i'm not quite sure search in matter. see mean here url:
http://www.launchrun.com/consealtest/conblockmic-circular.php
thanks can me shed light on subject!
<?php function selected( $val = "") { $units = isset( $_post['units'] ) ? $_post['units'] : null; echo ( $units == $val ) ? "checked='checked'" : ""; } $units = isset( $_post['units'] ) ? $_post['units'] : null; $dia = isset( $_post['dia'] ) ? $_post['dia'] : null; $wt = isset( $_post['wt'] ) ? $_post['wt'] : null; $l = isset( $_post['l'] ) ? $_post['l'] : null; $num = isset($_post['num']) ? $_post['num'] : null; $waste = isset($_post['waste']) ? $_post['waste'] : null; $surface = isset($_post['surface']) ? $_post['surface'] : null; $denom = ( ( $units == "us" ) ? 12 : 100 ); $coverage = ( ( $units == "us" ) ? 1000 : 92.9); $measurements = 'in or cm'; if( $units == 'us' ){ $measurements = 'in'; } if($units == 'metric') { $measurements = 'cm'; } 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); ?> <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" <?php selected("us")?> value="us" />s.a.e.</label> <label> <input type="radio" name="units" <?php selected("metric")?> 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 (<?php echo $length ?>):</td><td align="center"><input type='text' name='surface' value="<?php echo $surface ?>"/></td></tr> <tr class="calcrow"><td>diameter (<?php echo $measurements ?>):</td><td align="center"><input type='text' name='dia' value="<?php echo $dia ?>"/></td></tr> <tr class="calcrow2"><td>wall thickness ($measurements):</td><td align="center"><input type='text' name='wt' value="<?php echo $wt ?>"/></td></tr> <tr class="calcrow"><td>section length ($length):</td><td align="center"><input type='text' name='l' value="<?php echo $l ?>"/></td></tr> <tr class="calcrow"><td>number of sections:</td><td align="center"><input type='text' name='num' value="<?php echo $num ?>"/></td></tr> <tr class="calcrow"><td>waste variance % (please add in decimal form):</td><td align="center"><input type='text' name='waste' value="<?php echo $waste ?>"/></td></tr> <tr class="submit"><td colspan="2"><input type='submit' value='calculate'/></td></tr> <tr class="calcrow"> <td><i>gallons needed 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 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>
Comments
Post a Comment