Form submitting null values

1

I have this little form that should send the data filled in to the page "cad_real_qm.php". However, I have a function in javascript that checks if some fields are null and if it is, will issue an alert. However, when testo giving submit in the empty form, it presents the first alert and performs the registration with the empty fields in "cad_real_qm.php". How do I access the page already cited only if all the fields I need are filled?

Follow 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>
    
asked by anonymous 28.11.2017 / 16:26

1 answer

2

Failed to return false and add return on 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>
    
28.11.2017 / 16:42