Hi,
I'm a beginner with PHP. Created a form with one single input field that accepts a code. When a button is pressed, the code is validated. If the code isn't valid it should respond with the message "Please enter a valid code". If the code is a valid code, the message would be " Processing data".
I can't seem to get it to work. Since I'm a beginner on PHP, I thought of starting pretty straight forward, in the end this will be a complete form handling script.
I really would appreciate some advise.
Here's the code:
<html>
<title>Form code</title>
<body>
<?php
//a valid code 2518GA
function valid_code($str){
return(ereg('[1-9][0-9]{3}[]?[a-zA-Z]{2}$',$str));
}
if ($submit != "send" || !valid_code($code)){
echo"<form action=\"$PHP_SELF\" method=\"post\">";
if($submit && !valid_code($code)){
echo"Please enter a valid code";
}
?>
code:<input type="text" name="code" value="<?php echo $code ?>"><br>
<input type="submit" name="submit" value="send">
</form>
<?php
} else {
echo"process data";
}
?>
</body>
</html>