1

I'm new to laravel and am working on an existing project. I have a form that passes data to a Laravel controller:

<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>

Here is a simplified version of the function that gets run in the controller on submit:

function shareHint($hint_id) {
    $input = \Request::input();
    $passedemail = $input['email'];
}

How does $input['email'] get the email address:

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

as passed from this part of the form?

I don't see where the association comes from but it is passing.

If I wanted another form field how would I have access to it as part of the controller function?

Edit:

I believe Moppo is correct because this javascript is being run.

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)
}
5
  • are you saying that the input named share_email comes to the controller as $input['email'] ? Commented Jan 12, 2016 at 21:45
  • @Moppo Yes, that is what I am saying. Commented Jan 12, 2016 at 21:47
  • i've updated my answer Commented Jan 12, 2016 at 21:54
  • I believe I found the code altering input names, I added it to the question. Commented Jan 12, 2016 at 22:00
  • 1
    yes it's sent from the last line of the js code Commented Jan 12, 2016 at 22:11

1 Answer 1

1

If the input named share_email comes to your controller as email it could be that some middleware modifies the request altering the input name. So you should check the app's middlewares and see if some of them is altering the request.

Alternatively it could be that some javascript code alters the input name before sending the form

EDIT

Looking at the code shows that in fact is javscript that sends the 'email' input:

var a = new FormData;
a.append("hinturl", hinturl), a.append("email", email),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.