How do I check for an empty field in a form?

How do I check for an empty field in a form?

Page 1 of 1

3 Replies - 19498 Views - Last Post: 07 January 2009 - 10:18 PM Rate Topic: -----

#1 jacky123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-January 09

How do I check for an empty field in a form?

Posted 06 January 2009 - 01:51 AM

hi all,

How do I check for an empty field in a form?

Thanks
----------------------------
http://www.infysolutions.com
web site design an maintenance
Is This A Good Question/Topic? 0
  • +

Replies To: How do I check for an empty field in a form?

#2 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5063
  • View blog
  • Posts: 26,438
  • Joined: 10-May 07

Re: How do I check for an empty field in a form?

Posted 06 January 2009 - 01:55 AM

You can check it with empty().
Was This Post Helpful? 0
  • +
  • -

#3 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: How do I check for an empty field in a form?

Posted 06 January 2009 - 03:30 AM

If you have a submit button (which you probably do) you can put that text box contents inside a variable and do a little If Statement.
$text = $_POST['text'];
If ($text === "") {
Echo "Textbox Empty";
}



I use === not == because it is more accurate. Well it means exactly that.

This post has been edited by sam_benne: 06 January 2009 - 03:31 AM

Was This Post Helpful? 0
  • +
  • -

#4 PunkRocker277  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 07-January 09

Re: How do I check for an empty field in a form?

Posted 07 January 2009 - 10:18 PM

The easiest way is to do what no2pencil said,
You can do that like this:
<?php
$text = $_POST['text'];
if (empty($text )) {
echo "The field was empty";
}
?>


This post has been edited by PunkRocker277: 07 January 2009 - 10:20 PM

Was This Post Helpful? 1

Page 1 of 1