2
I have 2 forms, one by ajax and the other php normal. both forms are working, but when I run the php form without ajax it returns me the errors of the php form with ajax.
PHP Com ajax
if ($_SERVER["REQUEST_METHOD"] == "POST") {
PHP Sem ajax
if (isset($_POST['Btnlk'])){
If the conflict is not there I put all the code.
Form code with ajax
<form class="form1" method="POST" enctype="multipart/form-data">
<div id="ressult_log_succes"></div>
<div id="ressult_log_error"></div>
<p>E-mail</p>
<input type="text" name="Email_user" placeholder="Informe seu E-mail">
<p>Senha</p>
<input type="password" name="Senha_user" placeholder="Informe a sua senha">
<input type="submit" id="Bot_login" name="Logar_sn" value="Logar">
</form>
<script>
$(function(){
$(".form1").submit(function(event){
event.preventDefault();
var formDados = $(".form1").serialize();
$.ajax({
url:"/complement-of-archive/ConsultaLoginUser.php",
type:"POST",
data:formDados,
cache:false,
processData:false,
success:function(data){
$("#ressult_log_succes").html(data);
},
error:function(data){
$("#ressult_log_error").html(data);
},
dataType:"html"
});
return false;
});
});
</script>
My form without ajax
<form class="form2" method="POST" enctype="multipart/form-data">
<input type="hidden" name="ID_Pagina_LK_DL" value="2">
<input type="text" name="Usuario_LK_DL" value="" placeholder="Informe seu nome">
<input type="submit" name="Btnlk" value="1">
</form>
<?php
require_once('SysLKDLe.php');
?>
php from my form without ajax
<?php
if (isset($_POST['Btnlk']) && $_POST['Btnlk'] == "1") {
$LK_DL = 1;
$ID_Pagina_LK_DL = $_POST['ID_Pagina_LK_DL'];
$ID_Usuario_LK_DL = $_POST['Usuario_LK_DL'];
if ($LK_DL != 1) {
}
else{
$SQL_LK_DL = mysqli_query($conex,"INSERT INTO Banco_lk (LK_DL, Nome_LK_DL, IDUser_LK_DL) VALUES ('$LK_DL', '$ID_Pagina_LK_DL', '$ID_Usuario_LK_DL')");
}
}
?>
Man, both Forms are entering if do with ajax. After all, it validates only if the request was via POST. Or send a parameter in the request to identify which form was sent or change the HTTP verb, if possible.
– DiegoSantos