You can do this using AJAX in a simple way.
Considering the following form:
<form id="form-register">
<label for="inp-nome">Nome:</label>
<input type="text" id="inp-nome" />
<button type="submit">Enviar</button>
</form>
We treat your Submit (upload) event with the following Jquery code:
$('#form-register').submit(function(e) {
e.preventDefault();
var nome = $('#inp-nome').val();
var postForm = {
'nome': nome
};
$.ajax({
type: 'POST', // Usa o método POST
url: 'pagina.php', // Página que será enviada o formulário
data: postForm, // Conteúdo do envio
success: function(data) {
if (data == 'sucesso') {
alert('Foo');
} else {
alert('Bar');
}
}
});
});
Here is the PHP code that will insert into the database:
<?php
$nome = $_POST['nome'];
// Código de tratamentos/inserções no banco aqui
// Caso tenha inserido com sucesso
echo "sucesso";
// Caso contrário
echo "falha";
?>
Note that what you are really looking for is the AJAX part in the javascript code, you can deal with how the information will be returned in other ways (using the function .html()
for example).
I find it more that it lacks clarity than the question is too broad. Anyway, it depends on the author’s edits, complementing the content, so it can be reopened.
– bfavaretto
PHP, when used to display web pages, does not popup, because it runs on the server and not on the client. It would have to add JS code for this.
– Bacco