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)
}
share_emailcomes to the controller as$input['email']?