473,583 Members | 3,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.p hp" 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 12684
try

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

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

"Chris Portka" <ch*********@gm ail.com> wrote in message
news:11******** ************@g4 3g2000cwa.googl egroups.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.p hp" 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.p hp" 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
5918
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 are ignored? I have tried entering data such as `/bin/date > /tmp/1234` and this does not create a temporary file (which is what I would expect,...
5
7896
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
59317
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
312
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 how to do that...thanks ....
3
917
by: George Medlock | last post by:
How do you put a hyperlinked text on a blank form. Just a plain form Thanks
8
2767
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 static html templates and the form input is checked using a validation class. Basically each form field is checked, every error is stored to an array and...
1
1250
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 - id - Formatted as "DR-00000" - company - address
3
1599
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 problem: When I create a form it only dispays the data that is already imported without allowing me to change or modify any of the info should there...
6
1985
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 correctly. I am trying to debug an ex-employee's web code and seem to sinking here. Let me try to explain. We are receiving few blank submit forms via a...
0
7893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7821
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5695
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5369
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3813
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3839
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2326
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.