gpt4 book ai didi

php - 在 Laravel 中获取编辑表单上的选定选项

转载 作者:行者123 更新时间:2023-12-01 08:23:36 25 4
gpt4 key购买 nike

我的网站订单有一个可编辑的表单,我有以下字段:
User quantity note status
我在此表单中还有其他选项,但只有这些字段对我来说很重要,以便能够获得默认值。

例如,我希望能够查看用户默认订购的数量,然后我可以更改它或不理会它。目前我所有的下拉值都从第一个值开始,而不是用户选择的值。

我怎样才能做到这一点?

这是我的表格:

{{ Form::model($order, array('route' => array('orders.update', $order->id), 'method' => 'PUT', 'files' => true)) }}

<div class="form-group">
<label class="col-md-3 control-label" for="type">Order ID</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-word-o"></i></span>
<input class="form-control" type="text" name="" value="{{ $order->id }}" readonly>
</div>
</div>
</div>


<div class="form-group">
<label class="col-md-3" for="invoice_nu">Invoice Number:</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></span>
<input class="form-control" type="text" name="invoice_nu" value="{{ $order->invoice_nu }}" readonly>
</div>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label" for="type">User</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user-o"></i></span>
<select class="form-control" id="type" name="user_id">
@foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->name }}</option>
@endforeach
</select>
</div>
</div>
</div>



<div class="form-group">
<label class="col-md-3 control-label" for="type">Quantity</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-code-o"></i></span>
<select class="form-control" id="type" name="quantity">
<option value="">Select Quantity</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label" for="type">Note</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-word-o"></i></span>
<textarea name="name" class="form-control" rows="8">@if(!empty($order->note)){{ $order->note }}@else-@endif</textarea>
</div>
</div>
</div>


<div class="form-group">
<label class="col-md-3 control-label" for="type">Status</label>
<div class="col-md-9 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-code-o"></i></span>
<select class="form-control" id="type" name="status">
<option value="Waiting Payment">Waiting Payment</option>
<option value="Paid">Paid</option>
</select>
</div>
</div>
</div>


{{ Form::submit('Save', array('class' => 'btn btn-primary mt-20')) }}

{{ Form::close() }}

最佳答案

你可以比较$order->quantity带有要添加的选项值 selected属性

<select class="form-control" id="type" name="quantity">
<option value="">Select Quantity</option>
<option value="1" {{ $order->quantity == 1 ? 'selected' : '' }}>1</option>
<option value="2" {{ $order->quantity == 2 ? 'selected' : '' }}>2</option>
<option value="3" {{ $order->quantity == 3 ? 'selected' : '' }}>3</option>
<option value="4" {{ $order->quantity == 4 ? 'selected' : '' }}>4</option>
<option value="5" {{ $order->quantity == 5 ? 'selected' : '' }}>5</option>
</select>

供用户比较 $user->id$order->user_id (或其他根据您的数据)
<select class="form-control" id="type" name="user_id">
@foreach($users as $user)
<option value="{{ $user->id }}" {{ $user->id == $order->user_id ? 'selected' : '' }}>{{ $user->name }}</option>
@endforeach
</select>

关于php - 在 Laravel 中获取编辑表单上的选定选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45268471/

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