473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do you test for blank form input?

This is a very simple question but after a long time I still can't find
an answer looking on my own. How do you test for no user input in a
form? Example:

<form action="index.php" method="get">
Type your first name:
<input type="text" name="FirstName">
<input type="submit" value="Submit">
</form>

<?php
if ($_GET["FirstName"] == "")
{
echo "No user input";
}
?>

Is this the correct way to always test if there was nothing input by
the user in the form? Should I test for nil or something else?
Thanks,
Chris

Aug 18 '05 #1
6 12671
try

if (trim($var) == "") //empty
else //not empy

Aug 18 '05 #2
trim() and also look at empty()

"Chris Portka" <ch*********@gmail.com> wrote in message
news:11********************@g43g2000cwa.googlegrou ps.com...
This is a very simple question but after a long time I still can't find
an answer looking on my own. How do you test for no user input in a
form? Example:

<form action="index.php" method="get">
Type your first name:
<input type="text" name="FirstName">
<input type="submit" value="Submit">
</form>

<?php
if ($_GET["FirstName"] == "")
{
echo "No user input";
}
?>

Is this the correct way to always test if there was nothing input by
the user in the form? Should I test for nil or something else?
Thanks,
Chris

Aug 18 '05 #3
Chris Portka wrote:
<?php
if ($_GET["FirstName"] == "")
{
echo "No user input";
}
?>


how about:

if (isset($_GET['FirstName']) && empty($_GET['FirstName'])) {
echo "yes, it's empty";
}

Specifically the "empty" function will be useful here, but sometimes its
good to check that the variable actually exists.

/Marcin
Aug 18 '05 #4
Chris Portka wrote:
This is a very simple question but after a long time I still can't find
an answer looking on my own. How do you test for no user input in a
form? Example:

<form action="index.php" method="get">
Type your first name:
<input type="text" name="FirstName">
<input type="submit" value="Submit">
</form>

<?php
if ($_GET["FirstName"] == "")
{
echo "No user input";
}
?>

Is this the correct way to always test if there was nothing input by
the user in the form? Should I test for nil or something else?
Thanks,
Chris

I also use NULL some times...eg.
if ($_GET["FirstName"] == NULL)
Aug 18 '05 #5
if ( !isset($_GET['whatever']) || ( empty($_GET['whatever']) &&
$_GET['whatever'] != 0) )

Aug 18 '05 #6
BKDotCom wrote:
if ( !isset($_GET['whatever']) || ( empty($_GET['whatever']) &&
$_GET['whatever'] != 0) )


php.net/empty

"... As of PHP 4, The string value "0" is considered empty..."
Aug 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Reply Via Newsgroup | last post by:
Folks, I am using Apache 1.3.x with PHP 4.3.x and MySQL v4. Short question: Before I put my web form available on the internet, how can I test it from mis-use in such that special characters...
5
by: Batezz | last post by:
I have created a form (below) How do I stop it redirecting to another page (productsearchresults.php) when form is submitted if both the fields are blank? Any help appreciated. Batezz
4
by: chirs | last post by:
I try to test a field to see if it's empty. But it prints "It is not null". Why and how can I fix it? <html> <head> </head> <body> <input type="text" name="box1"> <script>
2
by: jervin via AccessMonster.com | last post by:
Good Day, I want to get rid of the blank form everytime i open. I had a form link with a query and i wanted to prompt me sayin "data not found" instead of showing a blank form. i just dont know...
3
by: George Medlock | last post by:
How do you put a hyperlinked text on a blank form. Just a plain form Thanks
8
by: Phil Latio | last post by:
I've been creating an application over the last few weeks and generally pleased with what I have produced but one area is irritating me, form validation. At the moment the forms are simply...
1
by: hexagram | last post by:
hi guys can anybody can teach me how to do this scenario Transfering Data of a form to a new form The Scenario is: I have a Delivery Receipt Form (Hardware) with a fields of the following ...
3
by: oli insight | last post by:
-------------------------------------------------------------------------------- Hi Guys, I've recently had a little go at access... I've learned a lot over the past few weeks but now i have a...
6
by: 0utlawza | last post by:
Hi Guys It seems i posted this in the incorrect topic, so i am reposting here. Please excuse the Newbie question. I am not really a programmer so excuse me if i dont clarify my point...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.