0
I am validating user access using the traditional method:
I would like that message to appear in a Modal Bootstrap. I tried the code below, but the bottom of the modal (black) and closes quickly, does not keep the modal open:
HTML
<form method="post" id="login-form">
<li>
<label id="texto">Login:</label>
<input required="required" type="text" name="LoginAcesso" id="usuario" placeholder="Matrícula" class="form-control" />
</li>
<li>
<label>Senha:</label>
<input required="required" type="password" name="SenhaAcesso" id="password" placeholder="Senha" class="form-control" />
</li>
<li class="text-right">
<button type="submit" name="submit" id="botao" class="btn btn-primary">Acessar</button>
</li>
</form>
MODAL
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Login e senha inválidos</h4>
</div>
<div class="modal-body">
<p>Tente novamente.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechr</button>
</div>
</div>
</div>
</div>
JQUERY
<script type="text/javascript">
$(document).ready(function(){
$('#login-form').submit(function(){
var login = $('#username').val();
var senha = $('#password').val();
$.ajax({
url : 'validar.php',
type : 'POST',
//dataType:"json",
data : 'login='+login+'&senha='+senha,
//beforeSend : function(){
// alert('01');
// $('#myModal').modal('show');
// },
success : function(data){
alert(data);
if(data == 1){
$('#myModal').modal('show');
}else{
alert('02');
}
}
});
});
});
</script>
VALIDATE.PHP
<?php
echo 1; // Teste
?>
Describe "It didn’t work", please. In jQuery there shouldn’t be a
.val()
when you set the value oflogin
andsenha
?– Woss
And in PHP, what are the values that come?
– Woss
When I give an Alert('login') or Alert('password'), the values do not arrive, even the fields filled.
– user24136
But
alert
inside the PHP file will not be executed because the code is not executed by the browser. In PHP dovar_dump($_POST)
and in jQuery, addconsole.log(data)
insuccess
.– Woss
actually Alert is inside jquery, after the line var password = $('#password');
– user24136
Then you should show up at least one
[object Object]
in the alert.– Woss
I got a little progress in the code. I’m now getting the value. With this I reformulated my question and updated the code.
– user24136
in var login = $('#username'). val(); is using username and in the form using id="user", will not return the value
– user60252
Hello Leo. The problem is that the Modal does not open. About the value informed, thank you for the observation. I made the adjustment.
– user24136