gpt4 book ai didi

javascript - 从javascript获取输入值时无法将值传递给 Controller

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

我在 Controller 中获取所有其他输入数据并将它们存储在数据库中,但我在输入字段中有 Total 但我无法在 Controller 中获取该数据。 Total 和其他输入字段的区别在于,我使用 javascript 获取 Total。任何我出错的地方,我认为我没有在 Controller 中提供正确的名称

checkout.blade.php

<div class="row">
{!! Form::open(['route'=>'address.store','method'=>'post'])!!}
{{ csrf_field() }}

<tr class="order-total">
<th>Total</th>
<td>
<strong>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">PKR.
<input style="border: none; background-color: #FFFFFF" id="Total" name="Total" disabled title="Total"></span>
</span>
</strong>
</td>
</tr>
{!! Form::close() !!}


<script>
$(document).ready(function(){
var span_Text = document.getElementById("SubT").innerHTML;
var del1 = 150;
var Total=+del1 + +span_Text;
$("#delivery").html(del1);
$("#note").html('Note: Delivery Charges will be Rs.150/-');
$("#Total").val(Total);

$('#location').change(function(){
var x = ($(this).val());

if(x === 'Other'){
if(span_Text >= 1500){
$('.formx').show();
var del2=200;
var Total1=+del2 + +span_Text;
$("#delivery").html(del2);
$("#note").html('Note: All Other Location Delivery Charges will be Rs.200/- and Order must of Rs.1500/-');
$("#Total").val(Total1);
}
else{
alert('Order must of Rs.1500/-');
$("#note").html('Note: All Other Location Delivery Charges will be Rs.250/- and Order must of Rs.1500/-');

}
}
else {
var Total2=+del1 + +span_Text;
$('.formx').hide();
$("#delivery").html(del1);
$("#note").html('Note: Delivery Charges will be Rs.150/-');
$("#Total").val(Total2);

}
});
});
</script>

Controller.php

   public function store(Request $request)
{
$this->validate($request,[
'fname'=>'required',
'lname'=>'required',
'Ttl'=>'required',
'email'=>'required|email',
'addressline'=>'required',
'city'=>'required',
'pro'=>'required',
'phone'=>'required |regex:/^[0-9\-\+]{9,15}$/',
'Total'=>'required'
//(0)[0-9]{9}
//|regex:/^[0-9\-\+]{9,15}$/
]);
Address::create($request->all());

return redirect('/')->with('valPrev',1);
}

最佳答案

问题出在disabled关键字,因为disabled字段没有提交。

因此您可以将输入设置为只读而不是禁用或添加隐藏输入,以便在像这样提交时获得值(value):

<span class="woocommerce-Price-currencySymbol">PKR.
<input readonly style="border: none; background-color: #FFFFFF" id="Total" name="Total" title="Total"></span>
</span>

对于隐藏输入:

<span class="woocommerce-Price-currencySymbol">PKR.
<input style="border: none; background-color: #FFFFFF" id="Total" disabled title="Total"></span>
<input type="hidden" id="TotalHidden" name="Total" ></span>
</span>

不要忘记更新 JavaScript 代码中的两个字段:

$("#Total").val(Total1);
$("#TotalHidden").val(Total1);
// and other places

关于javascript - 从javascript获取输入值时无法将值传递给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49066663/

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