Bootstrap表单无法检索SolveMedia POST数据 [英] Bootstrap form doesn't retrieve SolveMedia POST data

查看:91
本文介绍了Bootstrap表单无法检索SolveMedia POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Bootstrap模式下创建了一个表单来注册用户帐户:

I have created a form in a Bootstrap modal for user account registration:

<div class="modal-body">
    <form class="form-horizontal" id="registerForm">
      <div class="form-group">
        <label for="newUsername" class="control-label col-xs-3">Username</label>
        <div class="col-xs-9">
          <input type="text" class="form-control" id="newUsername" required>
        </div>
      </div>
      <div class="form-group">
        <label for="newPassword" class="control-label col-xs-3">Password</label>
        <div class="col-xs-9">
          <input type="password" class="form-control" id="newPassword" required>
        </div>
      </div>
      <div class="form-group">
        <label for="newPassword2" class="control-label col-xs-3">Password</label>
        <div class="col-xs-9">
          <input type="password" class="form-control" id="newPassword2" required>
        </div>
      </div>
      <div class="form-group">
        <label for="newEmail" class="control-label col-xs-3">E-mail</label>
        <div class="col-xs-9">
          <input type="email" class="form-control" id="newEmail" required>
        </div>
      </div>
    </form>
</div>

Ajax

$(document).on('submit', '#registerForm', function () {
        var username = $("#newUsername").val();
        var password = $("#newPassword").val();
        var email = $("#newEmail").val();

        $.post("registration.php", { new_user: username, new_psw: password, new_email: email}, function(data) {
                var result = $.parseJSON(data);
                if (result.error) {
                        if (result.err_code == 1) {
                                $('#newUsername').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
                        }
                        else if (result.err_code == 2) {
                                $('#newEmail').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
                        }
                }
        });
        event.preventDefault();
});

我想集成SolveMedia验证码,请按照以下步骤操作: https ://portal.solvemedia.com/portal/help/pub/php/

I want to integrate the SolveMedia captcha and i follow these steps to do it: https://portal.solvemedia.com/portal/help/pub/php/

所以我在</form>标记之前添加了以下代码:

So i added the following code before </form> tag:

<div class="form-group">
    <label class="control-label col-xs-3">Captcha code</label>
    <div class="col-xs-9">
        <?php echo solvemedia_get_html("my_key"); ?>
    </div>
</div>

<?php echo solvemedia_get_html("my_key"); ?>

<textarea name="adcopy_challenge" rows="3" cols="40"></textarea>
<input type="hidden" name="adcopy_response" value="manual_challenge"/>

问题在于表单处理文件无法检索SolveMedia POST字段:

The problem is that the form processing file doesn't retrieve the SolveMedia POST fields:

$_POST["adcopy_challenge"]
$_POST["adcopy_response"]

SolveMedia库文件(我包含在PHP中)中的

文件).

that are in the SolveMedia library file (that i included in my PHP file).

因此,我的表单发送除SolveMedia POST值之外的所有值. 根据帮助部分( https://resolvemedia.zendesk.com/hc/zh-CN/articles/203660514-Always-Receiving-incorrect-solution- )我必须确保该表单包含POST方法. Bootstrap表单中缺少的method="POST"可能是问题所在吗?

So my form send all values except the SolveMedia POST values. According to the help section (https://solvemedia.zendesk.com/hc/en-us/articles/203660514-Always-Receiving-incorrect-solution-) i have to be sure that the form includes a POST method. Could the missing method="POST" in the Bootstrap form be the problem?

推荐答案

以下是提交表单的Ajax代码

Following is the Ajax code to submit the form

$(document).on('submit', '#registerForm', function () {
        var username = $("#newUsername").val();
        var password = $("#newPassword").val();
        var email = $("#newEmail").val();

        $.post("registration.php", { new_user: username, new_psw: password, new_email: email}, function(data) {
                var result = $.parseJSON(data);
                if (result.error) {
                        if (result.err_code == 1) {
                                $('#newUsername').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
                        }
                        else if (result.err_code == 2) {
                                $('#newEmail').css({"border": "2px solid red", "box-shadow": "0 0 3px red"});
                        }
                }
        });
        event.preventDefault();
});

如果您仔细看,您分别为usernamepasswordemail创建了3个var,但是对于SolveMedia POST fields没有创建var,则需要创建SolveMedia POST fields,如

If you look closer, you have created 3 var each for username, password and email but there are no var for SolveMedia POST fields you need to create SolveMedia POST fields like

var username = $("#newUsername").val();
var password = $("#newPassword").val();
var email = $("#newEmail").val();
var challenge  = $("[name='adcopy_challenge']").val();
var response  = $("[name='adcopy_response']").val();

一旦您将创建SolveMedia POST fields var,并在此处使用Ajax发布其值以及其他输入值

once you will create SolveMedia POST fields var post it's values with Ajax here along with other input values

$.post("registration.php", { new_user: username, new_psw: password, new_email: email, challenge: adcopychallenge, response: adcopyresponse }

并且在PHP端获取SolveMedia POST fields

$_POST["adcopychallenge"]
$_POST["adcopyresponse"]

这篇关于Bootstrap表单无法检索SolveMedia POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆