Thanks again for your replies.
I added your suggested changes and added this:
if(empty($errors)) {
//if($_POST)
//{
which prevents the Form from submitting and the email from sending, if, for example, the Name is left empty…Error! Much thanks. Now, upon submit/continue, the Form(jBox) should close to allow access to the page it is blocking.Yet, it doesn’t.
I was provided this feedback: “How does your response object look like in console.log(response);? It needs to be an object. And when the ajax call was successful it should contain {success: true}”. I don’t see anything in dev tools > Console when the Form shows an error on the web page, nor anything when the Form succeeds.
Any help with getting the jBox to close and show ‘success’ is greatly appreciated. Here’s the current code:
var myConfirm;
$(document).ready(function() {
myConfirm = new jBox('Confirm', {
content: $('.my-jbox-form'),
width: 830,
height: 205,
cancelButton: 'Return Home',
confirmButton: 'Continue',
closeOnConfirm: false,
closeOnEsc: false,
confirm: function() {
$.ajax({
url: 'https://..../submit.php',
method: 'post',
data: {
name: $('#name').val(),
email: $('#email').val()
},
success: function (response) {
console.log(response);
if (response.success)
{
//close()
closeOnConfirm: true
alert('Success')
} else {
alert('You have an Error');
}
}
});
return false;
}.bind(this),
cancel: function() {
//disable(),
window.location.href = "/index.html";
}
}).open();
});
and the php:
<?php
header('Content-type: application/json');
$errors = array();
$data = array();
if (empty($_POST['name']))
$errors['name'] = 'Name is required.';
if (empty($_POST['email']))
$errors['email'] = 'Email is required.';
if ( ! empty($errors)) {
$data['success'] = false;
$data['errors'] = $errors;
}
echo json_encode($data);
if(empty($errors)) {
//if($_POST)
//{
$to = 'chrisj....@hotmail.com';
$subject = 'Thank You';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$message1 = $_POST['message'];
$headers = $name;
$headers = 'from: support@.....com';
$message1 .= "\r\n\r\nName: ".$_POST['name']." \r\n Email: ".$_POST['email']." ";
$message = "Hello {$_POST['name']}, ~ Thank you\r\n\r\n";
mail( $to, $subject, $message1, $headers );
mail( $email, $subject, $message, $headers );
$data[‘success’] = true;
echo json_encode($data);
exit;
}
?>