如何在同一页面上显示securimage错误

时间:2014-03-24 21:20:47

标签: php jquery validation spam-prevention

我在securimage website上找不到,在论坛上更新,如何在找到联系表单(带有反垃圾邮件代码)的同一页面上显示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;
    }
  });
});

1 个答案:

答案 0 :(得分:0)

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

我还需要另外安装另一个jquery文件,名为jquery.form.js,其中包含我不理解的代码...但是如果你有问题在同一页面上获得securimage的错误信息安装联系表格,让我知道,我会发给你js文件!