1

I'm building a simple form with a username and password.

When I construct a username field like this:

{{ Form::text('username') }}

My page loads without issue. As soon as I want to define a class like this:

{{ Form::text('username', ['class' => 'awesome']) }}

I get an error, like so:

ErrorException in HtmlBuilder.php line 65:
htmlentities() expects parameter 1 to be string, array given

Haven't been able to find any info regarding this error online. These examples are taken STRAIGHT from the LaravelCollective documentation.

Any ideas? Thanks!

Vranvs
  • 1,411
  • 4
  • 17
  • 38

4 Answers4

1

You should pass the class in the third parameter like so:

{{ Form::text('username', null, ['class' => 'awesome']) }}

or:

{{ Form::text('username', '', ['class' => 'awesome']) }}

The second parameter is the value field

Cameron Spanos
  • 250
  • 3
  • 14
0

If you are using Laravel 5 You should write like this:

{!! Form::text() !!}

Not like this:

{{ Form::text() }}

Also you have attributes array given as second parameter which is default value of this input. Please change it to:

{!! Form::text('your_name', null, ['class' => 'someclass']) !!}
Buglinjo
  • 2,067
  • 1
  • 15
  • 26
0

Looking at the source code, the expected parameters are:

Form::text($name, $value = null, $options = [])

The second parameter is for specifying a default value for the form element. So to define a class, you should pass the array to the third parameter:

Form::text('username', null, ['class' => 'awesome'])
Aken Roberts
  • 13,012
  • 3
  • 34
  • 40
0

If you are using laravel 5.4 you shouldn't use double curly for laravel collective html form like this

{{ Form::() }}

try this instead

{!! Form::text('username', $value = null, ['class' => 'awesome']) !!}
Yusuf
  • 71
  • 1
  • 8