我試圖通過AJAX進行的接觸形式jQuery和驗證引擎插件在http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/與驗證引擎AJAX接觸形式 - jQuery的
驗證工作,之前發送功能工作太...但
問題是它不能發送表單,並且它不能從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 = "[email protected]";
// 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.";
}
}
?>
任何人都可以幫我嗎?
在此先感謝!
添加'回聲json_encode($說Aviso);'到PHP文件的末尾..你不張貼任何東西:) –
它沒有工作: (,我不知道如何得到一個回調後「OnAjaxComplete」 – Ivan