Good morning,
I have these fields in an html form and I'm trying to validate it with php. In my validation with php, I need only one of the fields (any one) to be mandatory. In this case, the user must fill out at least one of the fields so that the form can be sent.
<input type="email" name="email" id="oemail" placeholder="Digite seu E-mail">
<input type="tel" name="whats" id="whats" placeholder="Digite seu whatsapp" maxlength="15">
<input type="tel" name="telefone" id="telefone" placeholder="Digite seu telefone" maxlength="14">
I am doing the validation with the following code. (working)
if (empty($whats) OR strstr($whats, ' ')==false) {
$erro = 1;
}
if ($erro != 0) {
echo '<script type="text/javascript">window.location = "erro.php";</script>';
exit;
}
I tried to use the following code, but as understanders can see, it does not work:
if (empty($whats) OR strstr($whats, ' ')==false) and (empty($telefone) OR strstr($telefone, ' ')==false) and (empty($email) OR strstr($email, ' ')==false) {
$erro = 1;
}
if ($erro != 0) {
echo '<script type="text/javascript">window.location = "erro.php";</script>';
exit;
}
The questions are as follows:
- For my problem, this is the most correct way to validate the form? If not, which one would be the best?
- How would I get the logic of the second try correctly within php?