I'm trying to do some error checking with PHP. I've got a javascript form that works good and I'm trying to create a PHP form that does the same thing.
One thing I want to check for is empty fields with an if else statement.
The javascript version looks like this.
function check_field()
{
var usr_name = document.getElementById('u_name')
if (usr_name.value.length == 0)
{
alert ("Field is empty")
return = false
}
else
{
alert ("This field has value")
}
}
<form action="test.htm" method="post" onsubmit "return= check_field()">
username: <input type="text">
<input type="submit" value="Submit">
</form>
And this is the PHP code I've tried.
function check_field()
$_POST["user_name"]
if $_POST.length["user_name"] == 0
echo "This field is empty";
else
echo "This field has value";
<form action="test.htm" method="post" onsubmit "return= check_field()">
username: <input type="text">
<input type="submit" value="Submit">
</form>
How do I specify the length value to say "If the length of the field is 0 then display the message 'Field is empty'"
Help!