2014-03-04 20 views
0

我有一個表格。當驗證失敗時,我重定向到同一頁面。 「mobilepage1.blade.php」我有一個表格。在

但是我的所有條目都沒有了。我希望我所有的參賽作品都留下來。輸入密碼。

我重定向我的網頁與View::make

return View::make('mobilepages.mobilepage1', array('errormessages' => 'errormessages')); 

我用:

$input = Input::all(); 

得到輸入。

回答

0

在表單視圖中,使用類似這樣的輸入:

<?= Form::text('title', (Input::get('title') ?: NULL)); ?> 

,如果它被設置並沒有什麼,如果它沒有設置(Input::get('title') ?: NULL)運營商將返回以前title值。

2

所有輸入

return Redirect::to('mobilepages')->withInput(Input::all()); 

除密碼

return Redirect::to('mobilepages')->withInput(Input::except('password')); 

Old Input

0

應該使用這樣的事情要做:

public formSubmitMethod() // Change formSubmitMethod with appropriate one 
{ 
    // This is the form submit handler 
    // Set rules and validate the inputs 

    $rules = array(...); // set rules here but there are other ways 

    $inputs = Input::except('_token'); // everything but _token 
    $validatior = Validator::make($input, $rules); 
    if($validatior->fails()) { 
     // Validation failed 
     return Redirect::back()->withInput()->withErrors($validatior); 
    } 
    else { 
     // Success 
     // Do whatever you want to do 
    } 
} 

在您的形式,使用Input::old('fieldname'),像這樣:

{{ Form::input('username', Input::old('fieldname')) }} 

就是這樣,現在如果你重定向回無效的用戶輸入,那麼你的表單字段將與舊值重新填充。不要在密碼字段中使用old()方法。您也可以使用類似{{ $errors->first('username') }}的字段訪問錯誤消息,因此如果此(username)字段無效,則會打印出該字段的錯誤消息。另外,請注意,爲了重定向回來,我使用了Redirect::back()而不是View::make(),它(make)不是用於重定向,而是用於呈現視圖以顯示它。

相關問題