如何将值传递给 Laravel 中的密码字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24886109/
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
How to pass value to Password field in Laravel
提问by Dev
I am trying to fetch value of the password field and display it in current form for one of the update pages
我正在尝试获取密码字段的值并以更新页面之一的当前形式显示它
{{ Form::label('Password')}}
{{ Form::password('password',array('class' => 'form-control') }}
Laravel blade's password field syntax does not allow parameter for input like it does for text fields for example,
Laravel Blade 的密码字段语法不允许像文本字段那样输入参数,例如,
{{ Form::label('Email or Username')}}
{{ Form::text('email',$useremaildata,array('class' => 'form-control')) }}
Now I found one solution of using placeholders like that but it is not the rite way of doing it. Sharing just incase.
现在我找到了一种使用这样的占位符的解决方案,但这不是这样做的仪式方式。分享只是以防万一。
{{ Form::label('Password')}}
{{ Form::password('password',array('class' => 'form-control','placeholder' => $userpassworddata)) }}
Any help will be great.
任何帮助都会很棒。
回答by alexrussell
The simple answer is that you don't do this. Password fields should rarely be pre-filled and so because it's not a common occurrence Laravel doesn't support it.
简单的答案是你不这样做。密码字段应该很少被预先填充,所以因为 Laravel 不支持它并不常见。
However, if you reallywant to do this you can use Form::input()
:
但是,如果你真的想这样做,你可以使用Form::input()
:
Form::input('password', 'name', 'value')
回答by theUtherSide
I think there are valid use cases for this. In my case, I am storing the password for another system, and when the user edits, I want to load the prior value from the database and fill it, so it doesn't get cleared when the user saves.
我认为这有有效的用例。就我而言,我正在存储另一个系统的密码,当用户编辑时,我想从数据库中加载先前的值并填充它,这样在用户保存时它就不会被清除。
Here's a custom HTML macro that allows you to set a default value in the password field.
这是一个自定义 HTML 宏,允许您在密码字段中设置默认值。
In start/global.php
do:
在start/global.php
做:
/**
* Custom macro for a masked password field with a default value
*/
HTML::macro('passwordWithDefault', function($name, $defaultValue = "", $optionsArray) {
return Form::input('password', $name, $defaultValue, $optionsArray);
});
Then in your HTML or template, you can use it like so:
然后在你的 HTML 或模板中,你可以像这样使用它:
HTML::passwordWithDefault('pwdField', Input::old('pwdField', $pwd_value),['class' => 'form-control'])