Laravel验证错误未显示,但确实在422错误中显示

问题描述 投票:0回答:1

我有一个简单的Web界面,可以在交易所上为个人加密货币交易选择特定的市场,价格,目标和止损。

[我添加了一些默认的laravel验证规则,其中一些规则应按其应有的方式显示在Web界面上,但是其中一个尤其不是在触发时,因为当我检查422 POST错误时,它确实会触发出现在响应中。

这里表单显示错误,止损部分除外,但止损错误未显示在Web界面上:

“”

我已将规则简化为仅具有“ require”(出于测试目的),对于更多规则,该规则也不起作用。规则:

'market' => 'required',
'trade_value' => 'required|numeric|min:10',
'limit-price' => 'sometimes|min:1|numeric',
'stop-price' => 'required',

422 POST的返回响应(laravel创建了这个?):

{
    "message":"The given data was invalid",
    "errors":{
    "market":[
        "The market field is required."
    ],
    "limit-price":[
        "The limit-price must be at least 1.",
        "The limit-price must be a number."
    ],
    **"stop-price":[
        "The stop-price field is required."
    ]**
}

每个请求的表单代码(我删除了该主题中未涉及的一些div):

<form method="POST" action="/trades" accept-charset="UTF-8" novalidate="" class="ajax-form"><input name="_token" type="hidden" value="sdgsdge563456">
           <!-- Default box -->
<div class="card ">
    <div class="card-header with-border" style="display:none;">
        <div class="float-left">

        </div>
        <div class="card-tools float-right">

        </div>
    </div>
    <div class="card-body">
        <div class="row">
               <div class="col-12">
                   <div class="form-group   required-field "><label for="market">Market</label><select class="form-control " id="market" name="market"><option selected="selected" value="">Select Market ...</option><option value="btc-perpetual">BTC-PERPETUAL</option><option value="eth-perpetual">ETH-PERPETUAL</option></select></div>
               </div>
           </div>
    </div>
    <!-- /.box-body -->
    <div class="card-footer" style="display:none;">

    </div>
    <!-- /.box-footer-->
</div>
<!-- /.box -->
           <!-- Default box -->
<div class="card ">
    <div class="card-header with-border" style="display:none;">
        <div class="float-left">

        </div>
        <div class="card-tools float-right">

        </div>
    </div>
    <div class="card-body">
        <div class="row">
               <div class="col-12">
                   <div class="form-group   required-field "><label for="trade_value">Trade Value</label><div class="input-group "><input class="form-control " placeholder="Trade Value" id="trade_value" name="trade_value" type="number" value="10"><div class="input-group-addon  input-group-append"><div class="input-group-text">USD</div></div></div></div>
               </div>
           </div>
    </div>
    <!-- /.box-body -->
    <div class="card-footer" style="display:none;">

    </div>
    <!-- /.box-footer-->
</div>
<!-- /.box -->
           <!-- Default box -->

<!-- /.box -->
           <!-- Default box -->
<div class="card ">
    <div class="card-header with-border" style="display:none;">
        <div class="float-left">

        </div>
        <div class="card-tools float-right">

        </div>
    </div>
    <div class="card-body">

           <div class="entrytype entrylimit">
               <div class="row">
                   <div class="col-12">
                       <div class="form-group   required-field "><label for="limit-price">Price</label><div class="input-group "><input class="form-control " placeholder="Price" id="limit-price" name="limit-price" type="number"><div class="input-group-addon  input-group-append"><div class="input-group-text">USD</div></div></div></div>
                   </div>
               </div>

           </div>
    </div>
    <!-- /.box-body -->
    <div class="card-footer" style="display:none;">

    </div>
    <!-- /.box-footer-->
</div>
<!-- /.box -->
        </form>```
php laravel validation laravel-blade rules
1个回答
0
投票

我已经解决了这个问题。

基本上,表单开始代码应该在3列div的前面,否则laravel将在第一个div之后停止验证。

© www.soinside.com 2019 - 2024. All rights reserved.