php Laravel 5 输入旧为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28624184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:59:43  来源:igfitidea点击:

Laravel 5 input old is empty

phplaravellaravel-5

提问by balkondemiri

My routes is here

我的路线在这里

Route::get('sign-up', ['as' => 'signUp', 'uses' => 'UserController@signUpGet']);
Route::post('sign-up', ['as' => 'signUpPost', 'uses' => 'UserController@signUpPost']);

Controller

控制器

return redirect('signUp')->withInput();

And View

并查看

    <form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
</form>

The {{old()}} function return empty value.
EDIT
I took

{{old()}} 函数返回空值。
编辑
我拿了

NotFoundHttpException in RouteCollection.php line 145:

回答by Laurence

Your problem looks like you are not actually submitting the username in the first place:

您的问题看起来您实际上并没有首先提交用户名:

<form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
</form>

There is no 'submit' button inside the form. If you submit outside the form - then the usernamewill not be included.

表单内没有“提交”按钮。如果您在表单之外提交 - 那么username将不包括在内。

Add the submit button inside your form - then try again

在表单中添加提交按钮 - 然后再试一次

<form role="form" method="POST" action="{{route('signUpPost')}}"> 
        <input type="text" class="form-control" name="username" value="{{ old('username') }}">
        <input type="submit" value="Submit">
</form>

Edit - also your controller is wrong. It should be this:

编辑 - 您的控制器也是错误的。应该是这样的:

 return redirect()->route('signUp')->withInput();

回答by Alejandro

All you are missing is to Flash the Input to the session. This is so it's available during the next request.

您所缺少的只是将输入闪存到会话中。这样它在下一个请求期间可用。

     $request->flash();

Do that just before calling to View your form.

在调用查看表单之前执行此操作。

Source: http://laravel.com/docs/5.1/requests#old-input

来源:http: //laravel.com/docs/5.1/requests#old-input

回答by Anonymouse

You can try this: {{ Input::old('username') }}.

你可以试试这个:{{ Input::old('username') }}

回答by AlmostPitt

I realize this isn't the case in this particular situation, but I ran into this problem as well. My problem here was caused by "data-prefill" in the input. Once I removed this, it worked.

我意识到在这种特殊情况下情况并非如此,但我也遇到了这个问题。我的问题是由输入中的“数据预填充”引起的。一旦我删除了它,它就起作用了。

Good luck everyone!

大家好运!

回答by yadu

            <div class="form-group @if($errors->first('username')) has-error @endif">
              <label for="username" class="rtl">Enter user name </label>
              <input type="text" name="username" class="form-control rtl basic-usage" id="username" placeholder="Enter user name" value="{!! old('username') !!}">
              <span class="help-block required">{{$errors->first('username')}}</span>
            </div>


above form field will show old value entered. will show validation error (you have to specify error separately.) have a place holder. bootstrap to look better.(add bootstrap)

上面的表单字段将显示输入的旧值。将显示验证错误(您必须单独指定错误。)有一个占位符。引导程序看起来更好。(添加引导程序)