gthuo
gthuo

Reputation: 2566

Laravel Error on Repopulating: htmlentities() expects parameter 1 to be string, array given in

I noticed that whenever I am redirecting back to the input form on error using withInput(), there is a very common error that will arise some times. ie

htmlentities() expects parameter 1 to be string, array given (View:[path])

I had realised that this only(usually) occurs whenever i redirect using withInput() but if i dont use it, the error does not occur, and neither are the firlds repopulated. I had however not known why this occurs until I thought avout it yesterday, and this is my view of it.

Upvotes: 1

Views: 2357

Answers (2)

Shamsi786
Shamsi786

Reputation: 159

I have the same problem but when i searches on this error i found that Laravel Input fields expects parameter 2 to be the value, and parameter 3 to be the array of attributes. So when you pass the attributes where the value should be, htmlspecialchars will flip out. or otherwise just remove the withInput option from the redirecting from controllers method it will work

Upvotes: 0

gthuo
gthuo

Reputation: 2566

One of the input fields in my form was a text box array, hence it had the same name like provinces[] in all the fields. Remember that Laravel's Input facade will get it as a variable and on redirecting, it will 'come back' with this variable (which in essence is an array) and load it with the first fields called like the array(provinces). When repopulating, Laravel will (i think) pass the original field value to the e() helper function (htmlentities() in reality), which expects parameter 1 as string but the array is given.

How i solved it: i renamed the fields so that i do not use an array for their names, so that all the fields have a distinct name. That worked for me.

In case my reasoning is flawed, you may correct me with love (and respect for Taylor) ;-)

(Well, as alexrussel had said in htmlentities() expects parameter 1 to be string, array given , this can also occur when in the Form::input() only three parameters are given instead of four.)

Upvotes: 1

Related Questions