gpt4 book ai didi

javascript - 从输入中检索数据 - laravel

转载 作者:行者123 更新时间:2023-11-30 20:25:38 27 4
gpt4 key购买 nike

使用下面的代码,当我提交表单时,数据库中的姓名和电子邮件字段保存为空。这告诉我无法检索输入,即使我使用正确的 name elements 作为输入。

我在这里做错了什么? HTML

  <form  action="/" class="fixed-form icons-tab-steps wizard-circle">
<!-- Step 1 -->
<h6><i class="step-icon ft-user"></i> Step 1</h6>
<fieldset>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="firstName2">Full Name :</label>
<input type="text" class="form-control square" id="name" value="{{$current_user->name}}" name="fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="lastName2">Email Address :</label>
<input type="text" class="form-control square" value="{{$current_user->email}}" id="lastName2" name="email">
</div>
</div>

<!-- Step 4 -->
<h6><i class="step-icon ft-layout"></i>Step 4</h6>
<fieldset>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="firstName2">Your Company :</label>
<input type="text" class="form-control square" id="name" name="company">
</div>
</div>
</div>

<div class="col-md-6">
<div class="form-group">
<label for="location2">Location :</label>
<input type="text" class="form-control square" id="name" name="location">

</div>
</div>

</fieldset>
</form>

JS

$(".icons-tab-steps").steps({
headerTag: "h6",
bodyTag: "fieldset",
transitionEffect: "fade",
titleTemplate: '<span class="step">#index#</span> #title#',
labels: {
finish: 'Submit'
},
onFinished: function (event, currentIndex) {

alert("Forms submitted.");

$.ajax({
method: 'GET', // Type of response and matches what we said in the route
url:'/user/update/2',
success: function(response){ // What to do if we succeed
console.log("paased");

},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
console.log("failed");

}
});
}

});


// Validate steps wizard

// Show form
var form = $(".steps-validation").show();

$(".steps-validation").steps({
headerTag: "h6",
bodyTag: "fieldset",
transitionEffect: "fade",
titleTemplate: '<span class="step">#index#</span> #title#',
labels: {
finish: 'Submit'
},
onStepChanging: function (event, currentIndex, newIndex)
{
// Allways allow previous action even if the current form is not valid!
if (currentIndex > newIndex)
{
return true;
}
// Forbid next action on "Warning" step if the user is to young
if (newIndex === 3 && Number($("#age-2").val()) < 18)
{
return false;
}
// Needed in some cases if the user went back (clean up)
if (currentIndex < newIndex)
{
// To remove error styles
form.find(".body:eq(" + newIndex + ") label.error").remove();
form.find(".body:eq(" + newIndex + ") .error").removeClass("error");
}
form.validate().settings.ignore = ":disabled,:hidden";
return form.valid();
},
onFinishing: function (event, currentIndex)
{
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinished: function (event, currentIndex)
{
alert("Submitted!");
}
});

// Initialize validation
$(".steps-validation").validate({
ignore: 'input[type=hidden]', // ignore hidden fields
errorClass: 'danger',
successClass: 'success',
highlight: function(element, errorClass) {
$(element).removeClass(errorClass);
},
unhighlight: function(element, errorClass) {
$(element).removeClass(errorClass);
},
errorPlacement: function(error, element) {
error.insertAfter(element);
},
rules: {
email: {
email: true
}
}
});

Controller

$user = User::whereId($id)->firstorFail();
$user->name = $request->get('fullname');
$user->email = $request->get('email');
$user->save();

最佳答案

获取输入参数的正确语法是使用方法input,而不是get:

$request->input('fullname')

此外,尝试使用 ddvar_dump 等方法调试您的代码,以查看变量包含的内容。例如:

$email = $request->input('email');
dd($email);

除此之外,还要确保属性 emailname 在您尝试分配的模型上是 $fillable

关于javascript - 从输入中检索数据 - laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50968544/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com