Hi,
I use the mailsnippet from Bastian on Gist.
My problem now is, how can I load the “thank you” or the URL here through AJAX?
Normally you set the jquery .ajax url to which the request is sent. But here is the action empty and the routing is completely realized through php if-requests. Also I have not idea what I have to do :).
Sorry for that nooby question but I’m really new to the ajax stuff and so please don’t hit me ;).
thanks for your reply. But I don’t understand how the alert will help me?
Normally I write a jQuery like that:
$(".selektor").submit(function() {
var url = "path/to/your/script.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $(".selektor").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
You can use Kirby’s r::ajax() method to check whether the request came from the form or your AJAX script (it returns true if it was an AJAX request). After processing the form data, you can then simply echo only the text you need instead of redirecting to another page:
// process the request data
// ...
if($email->send()) {
if(r::ajax()) {
echo 'Thank you!';
} else {
go('contact/thank-you');
}
}