dongyu5104 2019-02-21 16:40
浏览 64

带有Jquery表单验证插件的Wordpress中的PHP验证码

maybe it's a duplicate question, but i didn't find appropriate answers on it; most of them are relying on plugin and Bootstrap site. I made a custom contact form that send HTML email template via AJAX with Jquery form validation plugin which working great! And validation is working properly; but i have one problem to finish the task; i need to compare if the value entered in the field, is the value provided by the php captcha. Or is there any other solution that can check or restricted the right value in Jquery or Javascript. Here is my form validation:

  // form validation
        $('#contact_form').validate({

          onkeyup: false,
          onclick: false,
          debug: true,

              rules:{
                fullname:{
                  required :true,

                },
                email:{
                  required :true,

                },
                subject:{
                  required :true,

                },
                message:{
                  required :true,

                },
                securitycode: {
                    required :true,
                    remote: {
                      url: '/includes/captcha/check-captcha.php',
                      // type: 'post',
                      data: {
                        capvalue: function() {
                          return $( '#captcha' ).val();
                        }
                      }
                    }
                }
              },

              messages: {
                fullname: {
                 required: '*your name is required.'
               },
               email:{
                  required: '*email is required.'

               },
               subject:{
                 required: '*subject name is required.'
               },
               message:{
                    required: '*message is required.'

               },
               securitycode: {
                     required: '*Enter the right captcha code.'

               }
             }
      });

In the validation, i'm interested in rules for the field "securitycode"; i can't get the right url with some wordpress build functions. i get this error on the console log "GET http://localhost/includes/captcha/check-captcha.php?securitycode=05c25&capvalue= 404 (Not Found)"; the link missed only the root site folder name after the "localhost";

and the HTML file for the field check is:

    <div class=" captcha form-group captcha_style">
                                <input type="text" name="securitycode" id="securitycode" class=" form-control" maxlength="5">
                                <div class="button captcode">
                                    <img src="<?php bloginfo('template_url') ?>/includes/captcha/captcha.php" id="captcha" alt="Captcha"/>
                                    <span class="refresh-captcha"><i class="fa fa-refresh"></i></span>
                                </div>
                            </div>

i found a snippet to put in file check-captcha.php, like this :

<?php
if (!isset($_SESSION)) session_start();
if(strtolower($_REQUEST['securitycode']) == $_SESSION['captcha']) echo '1';
 else '0';



 ?>

Any contribution would be appreciate, Thanks!

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 shape_predictor_68_face_landmarks.dat
    • ¥15 slam rangenet++配置
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题