Zelf heb ik ajax jquery code al geschreven alleen weet niet hoe ik het kan omzetten naar json.
Dit is mijn code index.tpl.php:
<!DOCTYPE html>
<html>
<body>
<center><h2>Formulier</h2>
<form method="post" action="/leren">
Email:
<input type="text" id="email" name="email" class="resend-tickets-input"></p>
<br>
Ordernummer:
<input type="text" id="order-hash" name="order-hash" class="resend-tickets-input"></p>
<br><br>
</form>
<button type="submit" class="green-button icon-button">
<svg style="width:24px;height:24px" viewBox="0 0 24 24">
<path fill="#000000" d="M2,21L23,12L2,3V10L17,12L2,14V21Z"></path>
</svg>
Verzenden
</button>
</center>
<script>
$(document).ready(function(){
console.log("eey");
$("button").click(function(){
$.ajax({
type:'POST',
url: '/leren',
dataType:'json',
data:{"email": $('#email').val() , "order-hash": $('#order-hash').val(),},
success: function(data){
alert(data);
}});
});
});
</script>
</body>
</html>
Mijn controller index.ctr.php:
<?php
if (isset($_POST['email'])){
$gegevens = $_POST['email'] .' '. $_POST['order-hash'];
echo $gegevens;
exit;
}
?>