2014-03-24 38 views
0

我沒有找到也沒有在securimage website,在論壇上更加緊密如何顯示securimage錯誤消息在同一頁面上的聯繫表單(與反垃圾郵件代碼)被發現。如何在同一頁面上顯示securimage錯誤

我有我的聯繫方式:

<form id="contactform" action="processform.php" method="post">   
    <div class="form-label">Nom</div> 
    <input type="text" name="name" id="name" /> 
    <div class="form-label">E-mail</div> 
    <input type="text" name="email" id="email" /> 
    <div class="form-label">Sujet</div> 
    <input type="text" name="subject" id="subject" />         
    <div class="form-label">Message</div> 
    <textarea class="span6" rows="4" name="message" id="message"></textarea> 
    <div class="form-label-antispam">Anti-Spam Code</div> 
    <input type="text" name="verif" id="verif" size="10" maxlength="6" /> 
    <div id="verif-box"> 
     <img id="captcha" src="/securimage/securimage_show.php" alt="Security Code" /> 
     <a class="veriflink" href="#" onClick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">[Changer-Image]</a> 
    </div> 
    <input type="submit" id="send" name="button" value="Envoyer" />  
</form> 

我processform.php開始爲securimage需要,它給出了一個例子,但是這個例子引導我的錯誤信息到另外一個頁面:

<?php 

include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; 

$securimage = new Securimage(); 

if ($securimage->check($_POST['verif']) == false) { 
    // the code was incorrect 
    // you should handle the error so that the form processor doesn't continue 

    // or you can use the following code if there is no validation or you do not know how 
    echo "Le code de sécurité est incorrect.<br /><br />"; 
    echo "Retournez <a href='javascript:history.go(-1)'>à la page</a> et réessayez svp."; 
    exit; 
} 

我有一個contact.js文件,將其他輸入錯誤消息放入聯繫表單的同一頁的div中(與jquery.validate.min.js文件一起):

$(function() { 
    // Validate the contact form 
    $('#contactform').validate({ 
    // Specify what the errors should look like 
    // when they are dynamically added to the form 
    errorElement: "label", 
    wrapper: "div", 
    errorPlacement: function(error, element) { 
     error.insertBefore(element.parent().parent()); 
     error.wrap("<div class='error-wrap'></div>"); 
    }, 

    // Add requirements to each of the fields 
    rules: { 
     name: { 
     required: true, 
     minlength: 3 
     }, 
     email: { 
     required: true, 
     email: true 
     }, 
     message: { 
     required: true, 
     minlength: 20 
     } 
    }, 

    // Specify what error messages to display 
    // when the user does something horrid 
    messages: { 
     name: { 
     required: "Vous devez indiquer votre nom.", 
     minlength: jQuery.format("Le nom doit contenir minimum {0} caracteres.") 
     }, 
     email: { 
     required: "Vous devez indiquer votre email.", 
     email: "Vous devez indiquer un email valide." 
     }, 
     message: { 
     required: "Vous devez ecrire un message.", 
     minlength: jQuery.format("Le message doit contenir minimum {0} caracteres.") 
     } 
    }, 

    // Use Ajax to send everything to processForm.php 
    submitHandler: function(form) { 
     $("#send").attr("value", "Envoyer..."); 
     $(form).ajaxSubmit({ 
     target: "#response", 
     success: function(responseText, statusText, xhr, $form) { 
      $(form).slideUp("slow"); 
      $("#response").html(responseText).hide().slideDown("slow"); 
     } 
     }); 
     return false; 
    } 
    }); 
}); 
+0

您可以嘗試將所有內容放入同一頁面,並使用'action =「」'代替'action =「processform.php」' –

+0

我不知道如何將php代碼(processform.php)放入我的HTML頁面有contactform ...我不認爲這是解決方案...相反,我想我應該創建一個validation.js(因爲其他輸入字段),但我不知道該怎麼做。 –

回答

0

我得到了答案......

我需要安裝另一個jQuery的文件。此外,所謂jquery.form.js這是全碼是什麼我不明白的......但是如果你有問題在安裝聯繫表單的同一頁面上獲取securimage的錯誤消息,讓我知道,我會向您發送js文件!

相關問題