SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Mar 19, 2009, 12:40 #1
- Join Date
- Feb 2009
- Location
- Arizona
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
General question about checking a form field
I'm just curious which method you use to check the input is there, not how to validate or sanitize, but if you think 1 is better or why you use
Code PHP:if(!isset($_POST['txtField1']) { echo "Sorry that is a required field"; }
vs
Code PHP:if(empty($_POST['txtField1']) { echo "Sorry that is a required field"; }
it's just all about my making my code and clean and solid as possible.
Thanks
-
Mar 19, 2009, 13:17 #2
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I use empty() for strings, which is both an isset() check and a length check.
You can't use empty() for a field where 0 is a valid input.Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Mar 19, 2009, 13:25 #3
- Join Date
- May 2006
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You should avoid empty() in this case. I use
PHP Code:if ((!isset($_POST['txtField1']) || ($_POST['txtField1'] == ''))
{
echo "Sorry that is a required field";
}
Bookmarks