If all text fields are empty


I have a very simple form with just text fields (apart from submit & reset btns)

I want to simply test for whether or not ALL text fields in the form are empty… something like…

if(!isset($_GET[ all text fields ])


thank you…

You’ve already got the right structure.
&& = AND.
If FieldA is empty AND FieldB is empty AND…

oh man… I was hoping not to have to do it like that, was hoping for something slicker…:wink:
(can’t you put all values from text fields in an array like you can with values in checkboxes??)

thank you…

Yes, you can do that. You could also set up an array to check for errors, and then do something if there’s an error … But if you want to check specifically that all inputs are empty … StarLion’s seems worth considering to me. Why would you need to check for that specifically? (or are we taking you too literally?)

the trick is that text fields get sent (and set) even if they’re empty. Checkboxes dont get sent if they’re unchecked, so it’s easy to check checkboxes.

empty != isset

Checkboxes checker:

if(count($_POST['checkboxes']) == 0) { //No checkboxes set

Textfields are a little harder. Assuming an form-array named textboxes (You can use $_POST if the only things being posted are text fields)

if(array_sum(array_map('strlen',$_POST['textboxes'])) == 0) { //All text fields have an empty value.