Form sending null values

Asked

Viewed 69 times

1

I have this small form that should send the data filled in it to the page "cad_real_qm.php". However, I have a javascript function that checks if some fields are null and if so, will issue an alert. However, when I test giving Ubmit in the empty form, it displays the first alert and registers the empty fields in "cad_real_qm.php". How do I access the already mentioned page only if all the fields I need are filled?

Follows the code:

<form name="cad_ori" class="got" method="GET" onSubmit="verifica()" action="cad_real_qm.php" >
    <br>
    <center>
        <a class="got"> 1° server: </a>
        <input type="text" maxlength="15" placeholder="Servidor 1" name="ser1" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a class="got"> 2° server: </a> 
        <input type="text" maxlength="15" placeholder="Servidor 2" name="ser2" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a class="got"> 3° server: </a>   
        <input type="text" maxlength="15" placeholder="Servidor 3" name="ser3" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br /><br /><br />
        <a class="got"> Ori: </a>   
        <input type="text" maxlength="4" placeholder="Origem" name="ori" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a class="got"> Papel: </a>   
        <input type="text" maxlength="20" placeholder="Papel" name="pap" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br /><br /><br />

        <button class="css_btn_class" type="submit">Cadastrar</button> 
    </center>
    <br />
</form>

<script>
    function verifica()  {  
        if (document.cad_ori.ser1.value =='')  {  
            alert("Insira o ip do servidor 1!");  
            return;  
        } else if (document.cad_ori.ori.value =='')  {  
            alert("Insira a origem!");  
            return;  
        } else if (document.cad_ori.pap.value =='')  {  
            alert("Insira o papel!");  
            return;  
        } 
    }
</script>

1 answer

2


Failed to return false and add Return to onsumbit

function verifica()  {  
   
  if (document.cad_ori.ser1.value =='')  {  
    alert("Insira o ip do servidor 1!");  
    return false;  
  }else if (document.cad_ori.ori.value =='')  {  
    alert("Insira a origem!");  
    return false;  
  }else if (document.cad_ori.pap.value =='')  {  
    alert("Insira o papel!");  
    return false;  
  }
   
}
<form name="cad_ori" class="got" method="GET" onSubmit="return verifica()" action="cad_real_qm.php" >
        <br>
        <center>
        <a class="got"> 1° server: </a>
     <input type="text" maxlength="15" placeholder="Servidor 1" name="ser1" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a class="got"> 2° server: </a> 
     <input type="text" maxlength="15" placeholder="Servidor 2" name="ser2" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a class="got"> 3° server: </a>   
     <input type="text" maxlength="15" placeholder="Servidor 3" name="ser3" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br><br><br>
            <a class="got"> Ori: </a>   
     <input type="text" maxlength="4" placeholder="Origem" name="ori" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a class="got"> Papel: </a>   
     <input type="text" maxlength="20" placeholder="Papel" name="pap" style="width:100px;"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <br><br><br><br>

            <button class="css_btn_class" type="submit">Cadastrar</button> 
        </center>
        <br>
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.