PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
croniccoder
Forum Commoner
Posts: 27 Joined: Fri Jul 07, 2006 10:45 am
Post
by croniccoder » Fri Jul 21, 2006 1:29 pm
I am checking for an empty html form that is submitted using <input name="title" type="text>.
Code: Select all
$title = $_POST['title'];
if ($title == ' ')
{
print "<p>This is a required field. Please go back and fill it out.</p>";
}
else{
// process stuff
}
But this is not working and I can't figure out why. If I submit the title form and it is empty, the code still goes to the //process stuff.
any thoughts?
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Jul 21, 2006 1:30 pm
croniccoder
Forum Commoner
Posts: 27 Joined: Fri Jul 07, 2006 10:45 am
Post
by croniccoder » Fri Jul 21, 2006 1:33 pm
thanks man!
I tried the function, but I must have used it incorrectly the first time. It works fine now!
jmut
Forum Regular
Posts: 945 Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:
Post
by jmut » Fri Jul 21, 2006 3:45 pm
croniccoder wrote: thanks man!
I tried the function, but I must have used it incorrectly the first time. It works fine now!
you might want to trim() the input first...because empty will return false on " " (space).
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Fri Jul 21, 2006 5:20 pm
This is how I would check for an empty value..
Code: Select all
if ((!isset($_POST['title'])) or (trim($_POST['title']) == ''))
{
print "<p>This is a required field. Please go back and fill it out.</p>";
} else {
$title = $_POST['title'];
// process stuff
}