Tagged: x
-
AuthorPosts
-
March 3, 2017 at 6:10 am #1393193
DevRenanGasparParticipantHi,
I have created a new PHP file and placed under “x-child” folder. I can see it in the Appearance Editor – x-child theme already. The file name is “appointmentBooking.php” and has the following code:
<?php
if ($_POST) {
if (!$_POST[“name”]) {
$error .= “Favor adicionar o seu nome.<br>”;
}if (!$_POST[“email”]) {
$error .= “Favor adicionar o seu endereço de e-mail.<br>”;
}if (!$_POST[“datepicker”]) {
$error .= “Favor adicionar uma data.<br>”;
}if (!filter_var($_POST[“email”], FILTER_VALIDATE_EMAIL) && $_POST[“email”]) {
$error .= “Endereço de e-mail inválido.”;
}if ($error != “”) {
$error = ‘<div class=”alert alert-danger” role=”alert”>’.$error.'</div>’;
} else {
$emailTo = “coach@alinegaspar.com”;
$subject = “Solicitação de Agendamento de Sessão”;
$subject = ‘=?UTF-8?B?’.base64_encode($subject).’?=’;$headers = ‘MIME-Version: 1.0’.”\r\n”;
$headers .= ‘Content-type: text/html; charset=UTF-8’.”\r\n”;
$headers .= ‘From: ‘.$_POST[“email”];$content = ‘<html><body>’;
$content .= ‘Olá amor, <br><br>Uma cliente chamada ‘.$_POST[“name”];
$content .= ‘ solicitou uma sessão de coach com você para o dia ‘;
$content .= $_POST[“datepicker”].’ ‘.$_POST[“timepicker”];
$content .= ‘.<br><br>Seu endereço de e-mail é ‘;
$content .= $_POST[“email”].’ e telefone ‘.$_POST[“tel”];
$content .= ‘</body></html>’;
$content = html_entity_decode($content);if (mail($emailTo, $subject, $content, $headers)) {
echo ‘<div class=”alert alert-success” role=”alert”>Solicitação enviada! Favor aguardar o meu contato para confirmar a sessãoo.. foiCerto </div>’;
} else {
echo ‘<div class=”alert alert-danger” role=”alert”>hmmm… Algo saiu errado Por favor, envie e-mail direto para contato@alinegaspar.com!!</div>’;
}
}
}As you can see, it’s a form check and e-mail send.
I have created the form in HTML, for which I am using RAW CONTENT to place it in my page and it’s working great!
I am also using Custom JS to do some JS, JQUERY and Bootstrap customizations which is also working fine.
My problem is that I need to call the PHP file I created, after the user clicking Submit in my form. But I don’t want to have my page reloaded, that’s why I am using “PreventDefault” to prevent the page being reloaded, but I need to call that PHP code I created.
This is what my submit function is like:e.preventDefault();
alert(‘Begin’);
$.post(“appointmentBooking.php”, {}, function(data, status){});
alert(‘End’);Both alerts are displayed correct, but the php file is not called and therefor the e-mail not sent.
Would you please help me with this line between the alerts in order to make it call my php file?
Thanks. I searched a lot in the forum and on google as well, but couldn’t figure out how to resolve it.
Kind regards,
Renan Gaspar.March 3, 2017 at 7:39 am #1393252
DevRenanGasparParticipantUsing the Inspect from Chrome, I can see the error message:
XMLHttpRequest cannot load http://home/aline752/public_html/wp-content/themes/x-child/appointmentBooking.php. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://alinegaspar.com’ is therefore not allowed access. The response had HTTP status code 403.
March 3, 2017 at 8:45 am #1393319
DevRenanGasparParticipantHi,
I just figured it out, don’t worry about it anymore. The problem was the path, it has to be:
$.post(“/customfuncs/appointmentBooking.php”, {}, function(data, status){});
Thank you!
March 3, 2017 at 10:06 am #1393437
DarshanaModeratorGlad you were able to figure it out. Anyway custom development would be outside the scope of our support.
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1393193 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
