Просто измените isset($_POST['submit'])
на isset($_POST['btn'])
.
Когда вы отправляете свою форму, вы отправляете все имя ввода с помощью метода $_POST
.
Здесь у вас есть только ОДИН вход сname = 'btn'
.
Я делаю этот тест:
<?php
if (isset($_POST['btn'])) {
echo 'IT WORKS !';
}
?>
И он работает для меня, после нажатия на "Valider" я получил echo
:
![enter image description here](https://i.stack.imgur.com/W8qNQ.png)
Вот пример того, как вы можете попытаться сделать это, используя jQuery и Ajax.Я попытался объяснить, как это работает, и сделал пример, который редактирует ваш список книг, не перезагружая страницу при отправке.Надеюсь, это поможет!
$(document).ready(function() {
// When the form with id 'get_book_list' is sumbit, I will do something :
$("#get_book_list").on('submit', function(e) {
e.preventDefault();
// This is how an ajax call looks like (one example) :
// $.ajax({
// type: "POST", // the method you will use to send the data
// url: "yourfile.php", // the php file you want to call
// data : /* the data you want to send in your php file */,
// dataType: "json", // the data type you want to receive from the php file
// success: function(response){
// // Do something if the ajax call works : here you will edit your book list
// // 'response' is what the php will return, here imagine it's a JSON (dataType = 'json')
// },
// error: function(x,e,t){
// // Do something if the ajax call return error
// }
// });
//I will do the same but without the Ajax :
// 1/ Imagine you are in the success part of the ajax call
// 2/ This is the "response" you get from the php after the select :
var response = [{"book_name" : "title1"}, {"book_name" : "title2"}, {"book_name" : "title3"}];
// 3/ Now just edit your book_list to get what you want :
// I will build a list with each title
var book_list = "<ul>";
$.each(response, function(key, book) {
book_list += "<li>"+book.book_name+"</li>";
});
book_list += "</ul>";
// I add my list in my div
$('.book-list').html(book_list);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<div class="book-list">
<!-- here you will update the list of book -->
</div>
<form action="" method="post" id="get_book_list">
<input type="submit" name="btn">
</form>
</body>
</html>