2017-06-18 59 views
0

在Laravel,錯誤通常默認字段,其中數據輸入錯.I'm包圍示例enter image description hereLaravel如何拋出單個錯誤而表單字段沒有正確填寫

並且還示例代碼下顯示,我通常使用形式

<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> 
        <label for="name" class="control-label">Imie</label> 
        <div class="col-md6"> 
         <input id="name" maxlength="255" type="text" class="form-control" name="name" required autofocus> 
         @if ($errors->has('name')) 
          <span class='help-block'> 
           <strong>{{ $errors->first('name') }}</strong> 
          </span> 
         @endif 
        </div> 
       </div> 

我不想通知哪個領域沒有正確填寫用戶,但只顯示特定的錯誤全部輸入錯誤,如下面的截圖中看到。 如何才能做到這一點? enter image description here

---- ----編輯 感謝nyedidikeke和lewis4u的代碼,但我有輕微的問題,認爲負載之後我得到錯誤的文本,它是我的代碼它創建問題錯誤?

enter image description here

回答

2

我會建議刪除sinle輸入的所有錯誤消息,並只在頂部有一個這樣的:

@if (!empty($errors)) 
    <span class='help-block'> 
     <strong>{{ "Some input field is not properly filled" }}</strong> 
    </span> 
@endif 

,所有的輸入字段應該是這樣的:

<div class="form-group"> 
    <label for="name" class="control-label">Imie</label> 
    <div class="col-md6"> 
     <input id="name" maxlength="255" type="text" class="form-control" name="name" required autofocus> 
    </div> 
</div> 

而現在,如果你在任何領域都有錯誤,你會在最上面得到這個消息。

1

只需刪除該如果聲明顯示位於右側下方的<input>元素的錯誤,那麼你上面的表格,要顯示的消息,使用下面的代碼片段:

@if ($errors) 
    <span class='help-block'> 
     <strong>Wrong field form</strong> 
    </span> 
@endif 

這裏,我們向用戶顯示錯誤的字段格式,因爲填寫表單後提交嘗試後可能發生任何錯誤。

相關問題