Я пытался создать контактную форму через AJAX с подключаемым модулем jQuery и механизма проверки http://www.position -absolute.com / article / jquery-form-validator-потому-form-validation-is-a-mess /
Проверка работала и до отправки функция тоже работала ... но
Проблема заключается в том, что он не может отправить форму и не может вызвать из OnAjaxFormComplete
, что он будет "скрывать" форму с помощью jQuery. Используется для разработки.
Перейдите на http://bksn.mx/TAC/2/ нажмите большое название "Contacto", появится контактная форма, попробуйте.
Мой HTML-код формы:
<form id="formID" method="post" action="submit.php">
<div class="ajax">
<div class="idealWrap">
<label for="nombre">nombre:</label>
<input value="" class="validate[required] text-input" type="text" name="nombre" id="nombre"/>
</div>
<div class="idealWrap">
<label for="email">email:</label>
<input value="" class="validate[required,custom[email]]" type="text" name="email" id="email"/>
</div>
<div class="idealWrap">
<label for="tel">teléfono:</label>
<input value="" class="validate[custom[phone]] text-input" type="text" name="tel" id="tel" />
</div>
<div class="idealWrap">
<label for="mensaje">mensaje:</label>
<textarea value="" class="validate[required] text-input" name="message" id="message" ></textarea>
</div>
<div class="idealWrap">
<label> </label>
<input type="submit" id="submit" value=""/>
</div>
</div>
</form>
Вот мой сценарий:
function beforeCall(form, options) {
if (window.console)
alert("Right before the AJAX form validation call");
return true;
}
// Called once the server replies to the ajax form validation request
function ajaxValidationCallback(status, form, json, options) {
if (window.console)
console.log(status);
if (status === true) {
$('#formID').hide();
// uncomment these lines to submit the form to form.action
// form.validationEngine('detach');
// form.submit();
// or you may use AJAX again to submit the data
}
}
jQuery(document).ready(function () {
jQuery("#formID").validationEngine({
promptPosition: 'centerRight',
scroll: false,
ajaxFormValidation: true,
onBeforeAjaxFormValidation: beforeCall,
onAjaxFormComplete: ajaxValidationCallback,
});
});
и мой PHP-скрипт:
<?php
$aviso = "";
if ($_POST['email'] != "") {
// email de destino
$email = "vagnok@gmail";
// asunto del email
$subject = "Contacto";
// Cuerpo del mensaje
$mensaje = "---------------------------------- \n";
$mensaje.= " Contacto \n";
$mensaje.= "---------------------------------- \n";
$mensaje.= "NOMBRE: ".$_POST['nombre']."\n";
$mensaje.= "EMAIL: ".$_POST['email']."\n";
$mensaje.= "TELEFONO: ".$_POST['tel']."\n";
$mensaje.= "FECHA: ".date("d/m/Y")."\n";
$mensaje.= "HORA: ".date("h:i:s a")."\n";
$mensaje.= "IP: ".$_SERVER['REMOTE_ADDR']."\n\n";
$mensaje.= "---------------------------------- \n\n";
$mensaje.= $_POST['mensaje']."\n\n";
$mensaje.= "---------------------------------- \n";
$mensaje.= "Enviado desde TAC \n";
// headers del email
$headers = "From: ".$_POST['email']."\r\n";
// Enviamos el mensaje
if (mail($email, $subject, $mensaje, $headers)) {
$aviso = "Su mensaje fue enviado.";
} else {
$aviso = "Error de envío.";
}
}
?>
Кто-нибудь может мне помочь?
Заранее спасибо!