[英]Laravel Form::text styling with default value
I have tried the following code: 我尝试了以下代码:
{{ Form::text('username', 'Usuario', array('class' => 'form-control')) }}
But it fails, it throws this error: 但是失败了,它抛出了这个错误:
ErrorException
htmlentities() expects parameter 1 to be string, array given (View: /mydir/app/views/sessions/create.blade.php)
/mydir/vendor/laravel/framework/src/Illuminate/Support/helpers.php
* Escape HTML entities in a string.
*
* @param string $value
* @return string
*/
function e($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
}
}
I don't know if you want to fill in a default. 我不知道您是否要填写默认值。 Maybe you want to use a
placeholder
. 也许您想使用一个
placeholder
。 Try: 尝试:
{{ Form::text('username', null, array(
'class' => 'form-control',
'placeholder' => 'Usuario',
))
}}
The documentation api says: 文档api说:
/**
* Create a text input field.
*
* @param string $name
* @param string $value
* @param array $options
* @return string
*/
public function text($name, $value = null, $options = array())
{
return $this->input('text', $name, $value, $options);
}
It means that: 这意味着:
// ...is correct
Form::text( 'username', 'Usuario', array('class' => 'form-control') )
So that line is not the culprit. 所以那条线不是罪魁祸首。 You'd have to check the stack trace for what line it is giving the error at.
您必须检查堆栈跟踪以找出错误所在的行。
Update 更新资料
I saw you talking about a password field on the comments. 我看到您在评论中谈论密码字段。 The proper way of using the password field is:
使用密码字段的正确方法是:
public function password($name, $options = array())
{
return $this->input('password', $name, '', $options);
}
You asked: 您询问:
Ok I think it was that.
好吧,我认为是那样。 I had a default text for my password field.
我的密码字段有一个默认文本。 Can't I?
不能吗
The answer is 答案是
NO, you cannot.
你不能。 but you can try
Form::input
.但您可以尝试使用
Form::input
。
/**
* Create a form input field.
*
* @param string $type
* @param string $name
* @param string $value
* @param array $options
* @return string
*/
public function input($type, $name, $value = null, $options = array()) {
So do it like: ( warning untested code ) 就像这样:( 警告未经测试的代码 )
Form::input('password', 'passwordfield', 'defaultvalue', array('class' => 'myclass'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.