I have the following question. I have a simple registry and I want to register a new registry and tell me:
If the field is empty it shows me the message "Fill in the fields";
If it does not already exist, it will save to the bank;
Well, but I wanted to do this check in modal. I did the following tests:
INDEX.PHP
<html>
<title>Modal</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><scriptsrc="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
.modal-header, h4, .close {
background-color: #5cb85c;
color:white !important;
text-align: center;
font-size: 30px;
}
.modal-footer {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<form action="teste.php" method="post">
Nome: <input type="text" name="username" > <input type="submit" name="submit" value="Abrir sem modal" />
<div class="container">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Abrir com modal</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Teste Modal</h4>
</div>
<div class="modal-body">
<p><?php include 'teste.php'; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
TEST.PHP
<?php
require("conexao.php");
$nome = $_POST['username'];
if ($nome == "") {
echo "Preencha o campo";
} else {
$sql = mysql_query("SELECT nome FROM tb_visitas WHERE nome='$nome'");
if (mysql_num_rows($sql) > 0) {
echo "Valor duplicado";
} else {
echo "Gravando registro";
}
}
?>
On the "no modal" button it does the correct verification, is it possible to do the same with the modal?