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 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥15 Python3.5 相关代码写作
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗