I have two text input fields (weight and height). User inputs values. I want it to work like this:
- if the
submitButtonis not clicked: leave field empty - if the
submitButtonis pressed and user inputs non-integer: print "int" - if the
submitButtonis pressed and user inputs integer: keep the input visible
Validation is done, the point is to keep integer value visible in a field and text "int" if non-integer was provided until user inputs integers in both fields (and then clicks submitButton.
Forms:
<input type="text" name="height" value="<?=setValue( "height" )?>" size="4">
<input type="text" name="weight" value="<?=setValue1( "weight" )?>" size="4">
Conditions:
<?php
function setValue( $fieldName ) {
if (!isset($_POST["submitButton"]))
echo "";
elseif ((isset($_POST["submitButton"]) && ( is_int(isset( $_POST[$fieldName] ) ))))
echo $_POST[$fieldName];
elseif ((isset($_POST["submitButton"]) && ( !is_int(isset( $_POST[$fieldName] ) ))))
echo 'int';
}
function setValue1( $fieldName ) {
if(!isset($_POST["submitButton"])) echo "";
elseif ((isset($_POST["submitButton"]) && ( is_int(isset( $_POST[$fieldName] ) ))))
echo $_POST[$fieldName];
elseif ((isset($_POST["submitButton"]) && ( !is_int(isset( $_POST[$fieldName] ) ))))
echo "int";
}
Now when I input "1" in the height and press the submitButton I get "int" in both fields.