santa
santa

Reputation: 12512

At least one text field not empty

It must be an afternoon caffeine deprivation... stuck on a seemingly simple logic.

I have a form with many fields. I have 2 test fields. If both or at least one of them is not empty on POST I need to perform an action. This look quite convoluted, doesn't it?

if (($_POST['filed1'] != '' && $_POST['filed2'] != '') || 
    ($_POST['filed1'] != '' || $_POST['filed2'] != '')) {
     ...
}

Upvotes: 1

Views: 717

Answers (1)

IsisCode
IsisCode

Reputation: 2490

This should do it.

if(!empty($_POST['filed1']) || !empty($_POST['filed2'])){
    //do something
}

Upvotes: 3

Related Questions