laravel4-powerpack icon indicating copy to clipboard operation
laravel4-powerpack copied to clipboard

FormBuilder::open() wants an array?

Open jackperry opened this issue 11 years ago • 26 comments

My form open line is currently:

{{ Form::open('login', 'POST') }}

But it's returning this error:

ErrorException: Catchable Fatal Error: Argument 1 passed to Illuminate\Html\FormBuilder::open() must be of the type array, string given, called in /Users/jack/Projects/x/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 138 and defined in /Users/jack/Projects/x/vendor/laravel/framework/src/Illuminate/Html/FormBuilder.php line 77

Everything in the docs seems to be pointing to my Form::open line being correct, but I'm getting this. Ideas?

jackperry avatar Mar 10 '13 22:03 jackperry

Try

{{ Form::open('login',array('method' => 'POST')) }}

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

In addition, if you have updated to the latest build of Laravel (composer update) the new form class should work with the way you have it (thats how it is working for me). I know a recent update of From class was updated to support the original syntax.

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

I tried that and it didn't work, but I made it empty ({{ Form::open() }}) and it worked. However I'm sure this isn't a smart solution.

I am using the latest build of Laravel.

jackperry avatar Mar 10 '13 23:03 jackperry

The syntax you are using works fine for me. Make sure your composer.json file has (otherwise I have found Form and Str classes are updated correctly)

    "laravel/framework": "4.0.x-dev",

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

This code (snippet) works fine here

{{ Form::open('contacts.update','POST') }}

    {{ Form::hidden('id', $contact->id) }}
    {{ Form::hidden('page', Input::get('page')) }}

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

Ah, I was running "4.0.x" and not "4.0.x-dev", but I just changed it and did composer update and {{ Form::open('login','POST') }} still won't work. Same error.

jackperry avatar Mar 10 '13 23:03 jackperry

Any chance you have Meido forms or PowerPacks installed?

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

I have powerpack installed yeah.

jackperry avatar Mar 10 '13 23:03 jackperry

My guess it is conflicting since they both have same class names and method names. What features of PowerPacks do you need (use)? L4 latest pretty much has all that is in PowerPacks.

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

I installed PowerPacks for the HTML and Form classes. You're saying the latest Laravel 4 includes these now? Why was I getting the error before I switched to "4.0.x-dev" then, and I know HTML class wasn't found before I installed PowerPacks. Weird.

jackperry avatar Mar 10 '13 23:03 jackperry

Yes indeed (they will be installed with the -dev build)

Look in the "vendor/laravel/framework/src/illuminate/Html/" directory

You should have both FormBuilder and HtmlBuilder classes (now that you have updated to -dev)

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

Interesting, however even after removing the PowerPack classes, the dev ones are producing the same error (must be of the type array), even though you said it supports the old method. Is my install borked or something? o_O;;

jackperry avatar Mar 10 '13 23:03 jackperry

Did you do a composer update after removing PowerPacks from composer.json? I know it works (using it here no problem).

mikeerickson avatar Mar 10 '13 23:03 mikeerickson

I did, yep. Removed PowerPacks from composer.json, removed the providers and aliases from app.php, and ran composer update.

jackperry avatar Mar 10 '13 23:03 jackperry

So, the function declaration is as follows

public function open(array $options = array())

Not sure where the override is located?

mikeerickson avatar Mar 11 '13 00:03 mikeerickson

So that tells me the following should work

{{ Form::open(array('action' => 'login', 'method' = 'POST' )) }}

mikeerickson avatar Mar 11 '13 00:03 mikeerickson

Well, look at that! I still have PowerPacks installed so it appears that is what is actually being used as opposed to Laravel internal framework. That would explain why mine is still working.

mikeerickson avatar Mar 11 '13 00:03 mikeerickson

Sorry to lead you astray... This whole time I thought I had completely removed PowerPacks but alas I have not (I am still using it for HTML class operations) When I removed PowerPacks myself it broke my app big time and I don't have time to fix all the places at the moment so I have reinstalled.

mikeerickson avatar Mar 11 '13 00:03 mikeerickson

So, again this code should make it work for YOU (I will fix my code later)

{{ Form::open(array('action' => 'login', 'method' = 'POST' )) }}

mikeerickson avatar Mar 11 '13 00:03 mikeerickson

Haha, well that explains things! Thanks!

On Sunday, March 10, 2013 at 8:20 PM, Mike Erickson wrote:

So, again this code should make it work for YOU (I will fix my code later) {{ Form::open(array('action' => 'login', 'method' = 'POST' )) }}

— Reply to this email directly or view it on GitHub (https://github.com/laravelbook/laravel4-powerpack/issues/9#issuecomment-14692821).

jackperry avatar Mar 11 '13 01:03 jackperry

While I am new here I figured I would post how I got around this issue.

While the below throws and error: {{ Form::open('user/login', 'POST', array('id' => 'login-validate')) }}

If you just change the order and pou the extra options array first it works as expected. {{ Form::open(array('id' => 'login-validate'), 'user/login', 'POST') }}

Hope this helps.

codebyray avatar Mar 19 '13 08:03 codebyray

The conflict is with Illuminate\Html\HtmlServiceProvider as it is trying to reference the Html for Illuminate instead of the HTML package included.

Once I commented out: Illuminate\Html\HtmlServiceProvider in the providers and 'Html' => 'Illuminate\Html\HtmlBuilder', in the aliases it worked as expected.

Hopes this helps with fixing this issue.

Regards, Ray

codebyray avatar Mar 19 '13 08:03 codebyray

Or in the config/app.php, replace : 'Html' => 'Illuminate\Support\Facades\Html', by 'Html' => 'Illuminate\Support\Facades\HTML',

To avoid this problem, everything should be in camel case (URL => Url, DB => Db, HTML => Html, ...). Brief a single naming convention, not arbitrary as it is.

Nicolab avatar May 13 '13 10:05 Nicolab

Hi, I think we had the same problem. I found out that you should indicate a url variable in an array on the first parameter. Shows like this,

{{ Form::open(array('url' => 'foo/bar')) }}

I hope this would help.

ghost avatar Jun 29 '13 05:06 ghost

Hi, You can try this syntax, {{ Form::open(array('action' => 'login', 'method' => 'POST' )) }}

briiyaann avatar Jun 05 '14 03:06 briiyaann

My form open line is currently: {{ Form::open(array('action' => 'login', 'method' = 'POST' )) }}

But it's returning this error:

Argument 1 passed to Illuminate\Html\FormBuilder::open() must be of the type array, string given, called in /opt/lampp/htdocs/lara/lp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 211 and defined (View: /opt/lampp/htdocs/lara/lp/app/views/login.blade.php) Everything in the docs seems to be pointing to my Form::open line being correct, but I'm getting this. Ideas?

Ajaykatoch47 avatar Aug 20 '14 10:08 Ajaykatoch47