سؤال

when I search in Laravel 4 API, ex:

Form::open(array $options = array())

I can't find full list of available options? where to find it?

http://laravel.com/api/4.1/Illuminate/Html/FormBuilder.html#method_open

thanks,

هل كانت مفيدة؟

المحلول

See below link for specific options namely method,action,files,url and route

http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#63

Their usage is explained here

http://laravel.com/docs/html#opening-a-form

And you can add any other attributes you use in HTML as options, too.

نصائح أخرى

The options are:

  • method: POST, GET, PUT, PATCH, DELETE. The last three methods are spoofed with a hidden field.
  • action: sets action='...' attribute. If there is also a url, route option, they will be translated into the appropriate URL. Otherwise, the action should point to a Controller action route. If not present, the action defaults to current URL.
  • accept-charset: is forced to UTF-8
  • files: can be true if file upload is present, appends enctype = 'multipart/form-data' to the form.

toghether with any option you wish to add (like "id", "enctype" or similar).

You should probably check out at laravel official documentation

http://laravel.com/docs/html

Take a look at the source code: https://github.com/laravel/framework/blob/master/src/Illuminate/Html/FormBuilder.php#L95

Some complicated form:

Form::open(['method' => 'put', 'action' => 'awesomeController@putForm', 'id' => 'my-id', 'class' => 'some more css classes', 'files' => 'true', 'data-url' => 'This could be read in JavaScript']);

method, action and files are specific to Laravel, the other values are just attributes and values.

The list of options is the same list of form without use php:

http://www.w3schools.com/tags/tag_form.asp

The difference is that the attributes will be passed in array format:

array('action' => 'user.update', 'enctype' => 'multipart/form-data', 'method' => 'PUT')

The default method is POST, if not especified.

@edit

Seems that i didn't let clear.

Laravel only include some atributes to help, how url(converted to action), route(converted to action), file(converted to enctype='multipart/form-data'), but yet same thing.

file to enctype conversion:

if (isset($options['files']) && $options['files'])
{  
   $options['enctype'] = 'multipart/form-data'; 
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top