Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
02-28-2008, 05:51 PM #1
- Join Date
- Dec 2005
- Thanked 0 Times in 0 Posts
PHP Q:empty()/redirect/include() ?
empty($_post['submit']) this returns what for button "submit" non pressed / pressed ?
empty($_post['firstname']) this returns what for firstname field equals "", " ", (novalue-and press submit) ?
May use and isset() rather than empty() above, is the same ?
how in php I redirect user to a specific page eg. retrieve.php ?
php's include("file.html"); ?
02-29-2008, 02:30 AM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
isset is not exactly related to empty.
Isset is used to determine the existence of a variable, while empty is used to evaluate what that data includes.
Empty is a boolean result set, so it will return either true or false, and since php is a loosely typecasted language, false == 0 and true != false.
In your examples:
empty($_POST['submit']) on a correct submit returns false
empty($_POST['submit']) on a non-posted form returns true
empty($_POST['firstName']) on a value of "" returns true
empty($_POST['firstName']) on a value of " " returns false
on a side note, the value "0" as a string is also considered empty.
Isset is my recommendation for forms, and error checking is handled with empty and trim values.
For example. As I mentioned, special cases need to be done for numbers, as "0" in a string is empty, and I have no idea why they decided to program that way.PHP Code:
$_POST['firstName'] = trim($_POST['firstName']);
echo 'The value is empty, please enter the data.';
PHP redirects are done by adding headers to the request:
Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');