We help IT Professionals succeed at work.

best way to check if button pressed and text box as no value

avo42
avo42 asked
on
1,124 Views
Last Modified: 2008-03-06
Hi what is the best way to check an empty text box

at the moment im using

if ($_POST['sel_search'] && $_POST['prt_list']==""){

}
            elseif ($_POST['prt_list']!=""){

}


thanks in advance
Comment
Watch Question

I'm not sure you can get much better than what you have.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
aminerd,
Values processed by form is always STRINGS. So if you'll use type-sensitive === operator then you'll have some troubles.

For example:
<form>
<input type="text" name="int" />
<input type="submit" value="go" />
</form>

if you'll enter 123 to this form and press submit button, you'll have:
$_GET['int'] = '123';
not integer 123, but string '123':

<?php
if ($_GET['int'] === 123) { echo 'This won't work anyway!'; }
if ($_GET['int'] === '123') { echo 'This works!'; }
if ($_GET['int'] == '123') { echo 'And this works!'; }
if ($_GET['int'] == 123) { echo 'And this works too!'; }
?>

If you will not input anything in that field, then $_GET['int'] will be '', not NULL:
<?php
if ($_GET['int'] === NULL) { echo 'This won't work anyway!'; }
if ($_GET['int'] === '') { echo 'This works!'; }
if ($_GET['int'] == '') { echo 'And this works!'; }
?>

And if you'll put false (or true) in that field, it will also be 'false' or 'true', noy bollean false ore true:
<?php
if ($_GET['int'] === false) { echo 'This won't work anyway!'; }
if ($_GET['int'] == false) { echo 'This won't work too!'; } // Note this!
if ($_GET['int'] === 'false') { echo 'This works!'; }
if ($_GET['int'] == 'false') { echo 'And this works!'; }
?>
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi all

what would be the simplyes method to do that as i dont know javascript at all

thanks all for your input
CERTIFIED EXPERT
Top Expert 2006

Commented:
You cannot rely on javascript solely. Mazzachre should know better.

There are plenty people who are not using javascript and therefor can enter unvalidated data unless you also validate serverside.

-r-
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.