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
at the moment im using
if ($_POST['sel_search'] && $_POST['prt_list']==""){
}
elseif ($_POST['prt_list']!=""){
}
thanks in advance
I'm not sure you can get much better than what you have.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!'; }
?>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi all
what would be the simplyes method to do that as i dont know javascript at all
thanks all for your input
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-
There are plenty people who are not using javascript and therefor can enter unvalidated data unless you also validate serverside.
-r-