Link to home
Start Free TrialLog in
Avatar of avo42
avo42

asked on

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

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
Avatar of LinuxNubb
LinuxNubb
Flag of United States of America image

I'm not sure you can get much better than what you have.
SOLUTION
Avatar of TeRReF
TeRReF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!'; }
?>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of avo42
avo42

ASKER

Hi all

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

thanks all for your input
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-