Javascript 将表单数据从视图从表单传递到控制器

Javascript 将表单数据从视图从表单传递到控制器,javascript,php,html,laravel,Javascript,Php,Html,Laravel,我是拉威尔的新手,现在正在做一个现有的项目。我有一个表单可以将数据传递给Laravel控制器: <div class="share_popup" id="share_popup"> <div class="row"> <div class="col"> <div class="body"> <button class="x">

我是拉威尔的新手,现在正在做一个现有的项目。我有一个表单可以将数据传递给Laravel控制器:

<div class="share_popup" id="share_popup">
        <div class="row">
            <div class="col">
                <div class="body">
                    <button class="x">
                        <span class="sprite close"></span>
                    </button>

                    <div class="sprite logo"></div>
                    <!--<strong><span id="item_shared">Item name</span></strong>-->
                    <form id="email_form">
                        <input name="share_email" id="share_email" type="text" class="email" placeholder="Email" required>
                        <input name="share_name" id="share_name" type="text" class="name" placeholder="Name" required>
                        <input type="hidden" name="hint_id" id="hint_id" value="">
                        <span style="float:left;">Include a message below, if you'd like. test2</span><br/><br/>
                        <textarea name="message" id="message" placeholder="Message here..." class="description"> </textarea>

                        <button type="submit" onclick="shareHint(event)" id="share_button">Share</button>
                    </form>
                </div>
                </div>
        </div>
    </div>
$input['email']如何获取电子邮件地址:

<input name="share_email" id="share_email" type="text" class="email" placeholder="Email" required>

如果名为
share\u email
的输入作为
email
发送到控制器,则可能是某些中间件修改了请求,从而更改了输入名称。因此,你应该检查应用程序的中间件,看看其中是否有人在更改请求

或者,可能是一些javascript代码在发送表单之前更改输入名称

编辑

查看代码表明,实际上是发送“电子邮件”输入的javscript:

var a = new FormData;
a.append("hinturl", hinturl), a.append("email", email),

你是说名为
share\u email
的输入以
$input['email']
的形式发送到控制器?@Moppo是的,这就是我所说的。我已经更新了我的答案。我相信我发现了改变输入名称的代码,我将其添加到了问题中。是的,它是从js代码的最后一行发送的
function shareHint(e, hint_id){
    e.preventDefault();
    var email = $("#share_email").val();

    var hinturl = window.location.protocol + "//" + window.location.host + "" + window.location.pathname + "?h="+data.currentHint._id; 

    var r = new XMLHttpRequest;
    r.open("POST", "/hint/"+ hint_id +"/share"), r.addEventListener("readystatechange", function() {
        if (4 == r.readyState)
            if (200 == r.status){ 
                $(".share_popup").css('visibility', 'hidden');
                $("#share_email").val("");
                $("#message").val("");
                //alert("Successfully shared hint with " + email + "!")
                $("#alert_error").html("Successfully shared hint with " + email + "!");
                $("#alert_popup").addClass("visible");
            }else if (400 == r.status) {
            var e = JSON.parse(r.responseText);
            //alert(e.message)
            $("#alert_error").html(e.message);
            $("#alert_popup").addClass("visible");
        } 
        else{
            $("#alert_error").html('Sorry, an error occurred');
            $("#alert_popup").addClass("visible");
        // alert("Sorry, an error occurred")
        }
    });
    var a = new FormData;
    a.append("hinturl", hinturl), a.append("email", email), a.append("message", $("#message").val()),a.append("_token", csrf_token), r.send(a)
}
var a = new FormData;
a.append("hinturl", hinturl), a.append("email", email),