dimanche 26 mars 2017

$_POST can't make it check if both inputs are empty

I've got a form with some radio button options and a comment form like this:

<div>
  <input type="radio" name="field1" value="1">
  <input type="radio" name="field1" value="2">
  <input type="radio" name="field1" value="3">
  <textarea name="comment1"></textarea>
</div>

I've got around 5 divs like that. I am trying to check if the whole div got values, so both radio is checked and has some text in the textarea. This is the code I am currently using:

if (isset($_POST['field1'])) {
  // Check if Comment is empty echo special msg
} elseif (!empty($_POST['comment1'])) {
  // Check if radio is checked echo special msg
}

I don't want to check them both at the same time because there are some custom settings I have while checking each of them separately. The thing is IF the field1 is checked it will give an error that you need to fill comment1 too but if comment1 is not empty it won't give an error regarding the radio having no value.

Any ideas what I am doing wrong here? Tried variable options like isset on textarea/empty on radio, different IF's instead of elseif..

Aucun commentaire:

Enregistrer un commentaire