Some advice:
1) Stop opening and closing PHP so much... Echo exists for a reason.
2) if you're only doing a simple conditional check, don't waste the overhead of a function on it. (though I'd probably keep the preg one since that's more complex, the latter one is just silly)
3) if you're only doing output as a condition, don't waste an IF on it, use a inline eval.
4) you appear to be outputting XHTML, in which case it's checked="checked", not just checked.
5) if you have two functions returning the same operation, you should only have one value.
6) form elements are NOT a list and have perfectly good semantic meanings all their own -- so lose the list.
7) FOR on LABEL points at ID, not NAME
8) there is no reason after 2001 to put NAME on a FORM.
9) you're using radio buttons, which means they should have the same NAME and different VALUE -- you've got that backwards.
10) You've got some case mismatch's going on...
11) I'd suggest storing 'type' as just a number, not the string as that makes your logic more complex than need be. (numeric compares are typically faster than string anyways)
Code:
<?php
// assumes $type=$_POST['type'];
function invalidWH($str) {
return !(ereg ('^[0-9]{3,5}$' , $str));
}
if (
($submit!='Submit') ||
invalidWH($W) ||
invalidWH($H))
) {
echo '
<h3>Test Calculation</h3>
<form
id="test_calculation"
method="post"
action="',$_SERVER['PHP_SELF'],'"
>
<fieldset>
<legend>Type</legend>
<label for="type1">Type 1</label>
<input
type="radio"
name="type"
id="type1"
value="1"',(
$type=='1' ? ' checked="checked"' : ''
),'
/><br />
<label for="type2">Type 2</label>
<input
type="radio"
name="type"
id="type2"
value="2"',(
$type=='2' ? ' checked="checked"' : ''
),'
/><br />
</fieldset>
<div>
<input type="reset" name="reset" value="Reset" />
<input type="submit" name="submit" value="Submit" />
</div>
</form>';
} else {
echo '
<p>
The version is: ',$type,'
</p>';
}
Or something to that effect... See, same NAME, different ID, different VALUE.
Bookmarks