Ok, thanks, well, I added the header line and it now looks like this:
<?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($_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@web-site-name.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 );
//header('Location: https://web-site-name.com');
exit;
}?>
and the .js looks like this:
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) {
alert('Success');
} else {
alert('Error');
}
}
});
And Iâve tried to add: myConfirm.close(); into the .js code, but not sure where is the best place to put it.
After excuting the Form, still get a dialog box, on the Form page, that shows âhttp://âŚcom says Errorâ, yet the Formâs field info gets sent successfully.
And after Form submit, in the dev tools > Console it only shows one line,
[ ] upload.html:78
And, of course, the Form (jBox) doesnât close.
Any additional guidance/suggestions with call back and validation, and close() is appreciated.