Hi guys,
What's the best way to test for an empty form value ? I am doing it like
this now:
$test = $_POST['inputTest'];
if(strlen($test ) < 1)
// it is empty !
Maybe I can just go:
if($test == '') // that's two single-quotes with nothing in between
// it is empty !
At least I avoid a function call that way. Maybe there is a better way ?
Take care,
Cyrus 4 2313
Either way should work find, the second way may have less load on the
server, but honestly neither of them would cause too much... So
whatever is your preference. I ususally do it the second way and never
had a problem with it.
> What's the best way to test for an empty form value ? I am doing it like this now: $test = $_POST['inputTest']; if(strlen($test ) < 1) // it is empty ! Maybe I can just go: if($test == '') // that's two single-quotes with nothing in between // it is empty !
It has been my experience that the function "empty()" has not failed me.
If you have a string, "" or '' or "0" is empty.
If you have a numeric variable, 0 is empty
Arrays with no elements is empty
A class property that has been declared but not used (set) is empty
A boolean variable that is FALSE is empty
NULL values are empty
Any object with no properties set is empty http://www.php.net/empty
_______________ _______________ ______
Wil Moore III, MCP | Integrations Specialist | Assistant Webmaster $test = $_POST['inputTest']; if(strlen($test ) < 1) // it is empty ! Maybe I can just go: if($test == '') // that's two single-quotes with nothing in between // it is empty !
Also, do not forget, if you are testing for a key in an array such as your example: $_POST['inputTest'];
you can do isset($_POST['inputTest']) or you can use array_key_exist s('inputTest', $_POST)
If you KNOW the key is there, but you just want to know if it has a NULL or "empty" value, your best bet is to run it through the empty() function.
_______________ _______________ ______
Wil Moore III, MCP | Integrations Specialist | Assistant Webmaster
The foolproof way to check for an empty string is always strlen($var) < 1.
You may also want to use trim() to remove any leading/trailing spaces.
--
Tony Marston http://www.tonymarston.net
"Cyrus D." <sa***@invalid. org> wrote in message
news:p7******** *************@n ews4.srv.hcvlny .cv.net... Hi guys,
What's the best way to test for an empty form value ? I am doing it like this now:
$test = $_POST['inputTest']; if(strlen($test ) < 1) // it is empty !
Maybe I can just go:
if($test == '') // that's two single-quotes with nothing in between // it is empty !
At least I avoid a function call that way. Maybe there is a better way ?
Take care, Cyrus
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: n_o_s_p_a__m |
last post by:
My xml doc has many <title></title> and <title> in it, meaning the
nodes have no content (although some do). How can I test for this?
I tried title (doesn't work)
I tried //title (doesn't work)
I tried //title (doesn't work)
I tried //title (doesn't work)
Any suggestions welcome.
|
by: WindAndWaves |
last post by:
Hi Folks
I have inhereted a script that I understand reasonably well, I just do not
understand
!/^\d+$/.test(el.value)
what the hell does that mean?
Below is the script (there are really three and they validate a four items
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to use.
The above URL is version 1.0 (draft) that resulted. IMO, it is not a
replacement for the FAQ,...
|
by: Gertjan van Heijst |
last post by:
Hi,
I really hope someone can help me because I've already spend 2 days on
this problem and I'm not getting anywhere. I think the problem is that
I don't really understand how text boxes store 'empty' values. I'm
trying tot do the following.
I have a continous sub form that lists transactions. On the top level
form I have some text boxes to let the user specify the transactions
between which dates should be listed. To do this I have...
|
by: EDOnLine |
last post by:
New asp.net/webform user question......
I am trying to use the Custom Validator control to check to see if either of
two fields on my form have been filled in. At this point all I am
interested in is if the user has entered a value into EITHER input box (not
left blank). Below is my control code and also my function. I guess my
question is, What should I be testing for in my function? I have tried many
things (checked the length of...
| |
by: Anonieko Ramos |
last post by:
ASP.NET Forms Authentication Best Practices
Dr. Dobb's Journal February 2004
Protecting user information is critical
By Douglas Reilly
Douglas is the author of Designing Microsoft ASP.NET Applications and
owner of Access Microsystems. Doug can be reached at
doug@accessmicrosystems.com.
--------------------------------------------------------------------------------
|
by: Little |
last post by:
I have this program and I need to work on the test portion, which tests
if a Val is in the list. It returns false no matter what could you look
at the part and see what might need to be done to fix it. It reads in
the file and sorts out the files into the four different lists.
F.txt
int main
2
" "
help
|
by: h7qvnk7q001 |
last post by:
I'm trying to implement a simple server-side form validation (No
Javascript). If the user submits a form with errors, I want to
redisplay the same form with the errors highlighted. Once the form is
correct I need to submit to another page that uses the form data.
I first tried making the form submit action= field point to the same
file. When the form was correct, I tried loading the next page by using
<META http-equiv refresh>. But...
|
by: Muchach |
last post by:
Hello,
Ok so what I've got going on is a form that is populated by pulling
info from database then using php do{} to create elements in form. I
have a text box in each table row for the user to enter input. I need
to take this user input and put it back into the database. What would
be the best method to do this. I can't use a normal post because the
name of the text box is the same for each table row. I've heard that
posting the...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |