Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

unobab123's avatar

error in laravel 4.3

htmlentities() expects parameter 1 to be string, array given (View: /Users/unobab/laravel43/resources/views/auth/register.blade.php)

0 likes
9 replies
JeffreyWay's avatar

Any time that you report a bug, you must provide specifics. It's not helpful to anyone if you don't.

2 likes
thepsion5's avatar

It's probably gremlins. You'll need to include the gremlin cleaner package in your composer.json and add its service provider. Then, the gremlins will automatically be purged before a dump-autoload.

1 like
Devon's avatar
Devon
Best Answer
Level 18

Given that it's occurring in a template file named registration, I'm going to assume that it's Form related.

In that case, it often happens when you neglect to pass a string as the 2nd argument ($value) to the FormBuilder's email(), hidden(), text(), or url() methods or as the 3rd argument ($value) on the input() method... For example, something like this:

// Both of these will show the following error...
// htmlentities() expects parameter 1 to be string, array given
{{ Form::text('test', ['class' => 'form-control']) }}
{{ Form::input('text', 'test', ['class' => 'form-control']) }}

Should be:

{{ Form::text('test', null, ['class' => 'form-control']) }}
{{ Form::input('text', 'test', null, ['class' => 'form-control']) }}

This happens because the attributeElement() method in the HtmlBuilder doesn't check that the value is_string() before running it through e() which is a helper method that executes htmlentities()

 protected function attributeElement($key, $value)
 {
     if (is_numeric($key)) $key = $value;

     if ( ! is_null($value)) return $key.'="'.e($value).'"';
 }
Devon's avatar

No problem, I'm glad that worked!

However, in the future, help us help you. In other words, and as Jeffrey was saying, please try to include more information on the problem you're getting. You'd probably have received an answer a lot quicker if you had. :)

nanosolutions's avatar

HI Guys,

SO what's the fix I am having same issue when i Use array[] as name of text field. Thanks

nanosolutions's avatar

I have tried

{{ Form::text("answers[$question->q_id][]",null,array('class'=>'input-xlarge','placeholder'=>'Happy')) }}

Please or to participate in this conversation.