GithubHelp home page GithubHelp logo

html's Introduction

LaravelCollective HTML

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

Official documentation for Forms & Html for The Laravel Framework can be found at the LaravelCollective website.

Replacement

If you're looking to replace this package due to it's retirement we recommend using Shift

html's People

Contributors

adambant avatar adamgoose avatar alexandre-butynski avatar anahkiasen avatar andersonfriaca avatar barryvdh avatar crynobone avatar darthrevan13 avatar devinfd avatar franzliedke avatar grahamcampbell avatar greggilbert avatar lanort avatar laravel-shift avatar lucasmichot avatar maddhatter avatar mlantz avatar mul14 avatar nickurt avatar pjona avatar ranabd36 avatar robinmalfait avatar taylorotwell avatar thujohn avatar thunderbirdsx3 avatar tortuetorche avatar tshafer avatar vendin avatar vlakoff avatar yajra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

html's Issues

Checkboxes and attribute casting

When using Eloquent Attribute casting for an array the checkbox is not able to retrieve the model value. It thinks the model is an object but the accessed attribute is an array, that leads to the object_get method returning null. A possible quickfix is converting every model to an array.

    /**
     * Create a new model based form builder.
     *
     * @param  mixed  $model
     * @param  array  $options
     * @return string
     */
    public function model($model, array $options = array())
    {
        $this->model = $model->toArray();

        return $this->open($options);
    }

Maybe someone can come up with a better way to manage that.

Issue with Form::date() when using form-model binding

When null is being passed as the value to Form::date() to allow form-model binding to automatically set it, it's not being formatted into Y-m-d as it would be if the value were to be input manually. Instead it's the full DateTime string.

Form::model() // edit.blade.php
Form::date('started_at', $model->started_at, $options) //_form.blade.php
// returns properly

Form::model() // edit.blade.php
Form::date('started_at', null, $options) // _form.blade.php
// returns full DateTime and doesn't get treated properly by the browser

Form::open() // create.blade.php
Form::date('started_at', $model->started_at, $options) // _form.blade.php
// throws an exception, as $model doesn't exist yet

Form::open() // create.blade.php
Form::date('started_at', null, $options) // _form.blade.php
// treated properly by browser

[Proposal] About Form::text();

Hello, I've used

Form::text($name, $value, $attributes);

may it switch to ?

Form::text($name, $attributes, $value);

I think I alway use class or id and placeholder $attributes more than the $value,

Because people usually use Form::model and when they used Form::model and want to use $attributes

they alway do the long string of this.

{!! Form::text('name', isset($category->name) ? $category->name : '', ['class' => 'someclass' , 'id' => 'name']) !!}

But if we switch to

they will be use like this

if they don't want value
{!! Form::text('name', ['class' => 'someclass' , 'id' => 'name']) !!}

// if they want value
{!! Form::text('name', [], 'somevalue') !!}
or
{!! Form::text('name', ['class' => 'someclass' , 'id' => 'name'], 'somevalue') !!}

It will be shorten than the first one right ?

Best regards.

Can you tag a new version, please?

I am using laravelcollective/html as a dependency (through composer.json), but applying newest tests (current tests/FormBuilderTests.php) - and one test fails to pass (testFormRepopulationWithMixOfArraysAndObjects).

Current implementation of FormBuilder::getModelValueAttribute fixes it, while implementation of latest tagged version (5.0.4) fails to pass.

Can you please add a new version tag (5.0.5) so I can have a tests-proof version using composer?

Thank you.

deploying to heroku - PHP fatal error: Class 'Collective\Html\HtmlServiceProvider' not found

Hello

I'm trying to deploy my laravel project to heroku. Application works fine locally, but when I try to deploy it on heroku i get the following error:

Writing objects: 100% (9/9), 1.01 KiB | 0 bytes/s, done.
Total 9 (delta 6), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> PHP app detected
remote: -----> Resolved composer.lock requirement for PHP to version 5.6.10.
remote: -----> Installing system packages...
remote: - PHP 5.6.10
remote: - Apache 2.4.10
remote: - Nginx 1.6.0
remote: -----> Installing PHP extensions...
remote: - mbstring (composer.lock; bundled)
remote: - zend-opcache (automatic; bundled)
remote: -----> Installing dependencies...
remote: Composer version 1.0.0-alpha10 2015-04-14 21:18:51
remote: Loading composer repositories with package information
remote: Installing dependencies from lock file
remote: Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
remote: - Installing jakub-onderka/php-console-color (0.1)
remote: Downloading: 100%
remote:
remote: - Installing vlucas/phpdotenv (v1.1.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/var-dumper (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/translation (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/routing (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/process (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/http-foundation (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/event-dispatcher (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing psr/log (1.0.0)
remote: Downloading: 100%
remote:
remote: - Installing symfony/debug (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/http-kernel (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/finder (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/dom-crawler (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/css-selector (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing symfony/console (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing swiftmailer/swiftmailer (v5.4.1)
remote: Downloading: 100%
remote:
remote: - Installing nikic/php-parser (v1.3.0)
remote: Downloading: 100%
remote:
remote: - Installing jakub-onderka/php-console-highlighter (v0.3.2)
remote: Downloading: 100%
remote:
remote: - Installing dnoegel/php-xdg-base-dir (0.1)
remote: Downloading: 100%
remote:
remote: - Installing psy/psysh (v0.4.4)
remote: Downloading: 100%
remote:
remote: - Installing nesbot/carbon (1.20.0)
remote: Downloading: 100%
remote:
remote: - Installing mtdowling/cron-expression (v1.0.4)
remote: Downloading: 100%
remote:
remote: - Installing monolog/monolog (1.14.0)
remote: Downloading: 100%
remote:
remote: - Installing league/flysystem (1.0.4)
remote: Downloading: 100%
remote:
remote: - Installing jeremeamia/superclosure (2.1.0)
remote: Downloading: 100%
remote:
remote: - Installing doctrine/inflector (v1.0.1)
remote: Downloading: 100%
remote:
remote: - Installing danielstjules/stringy (1.9.0)
remote: Downloading: 100%
remote:
remote: - Installing symfony/filesystem (v2.7.1)
remote: Downloading: 100%
remote:
remote: - Installing classpreloader/classpreloader (1.4.0)
remote: Downloading: 100%
remote:
remote: - Installing laravel/framework (v5.1.3)
remote: Downloading: 100%
remote:
remote: Generating optimized autoload files
remote: PHP Fatal error: Class 'Collective\Html\HtmlServiceProvider' not found in /tmp/build_44f0e34f5ede5fd47193377db8b28292/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
remote:
remote:
remote:
remote: [Symfony\Component\Debug\Exception\FatalErrorException]
remote: Class 'Collective\Html\HtmlServiceProvider' not found
remote:
remote:
remote:
remote: Script php artisan clear-compiled handling the post-install-cmd event returned with an error
remote:
remote:
remote:
remote: [RuntimeException]
remote: Error Output: PHP Fatal error: Class 'Collective\Html\HtmlServiceProvider' not found in /tmp/build_44f0e34f5ede5fd47193377db8b28292/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
remote:
remote:
remote:
remote: install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [--ignore-platform-reqs] [packages1] ... [packagesN]
remote:
remote:
remote:
remote: ! Push rejected, failed to compile PHP app
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to alican.
remote:

Form::button allows HTML, Form::submit doesn't.

{!! Form::button('<i class="fa fa-plus"></i> '.Lang::get('location.button_create'), array('class' => 'btn btn-primary')) !!}

^^ OK!

{!! Form::submit('<i class="fa fa-plus"></i> '.Lang::get('location.button_create'), array('class' => 'btn btn-primary')) !!}

^^ doesn't work.

schermafbeelding 2015-09-16 om 14 55 37

The only difference is the submit v.s. button. Is this a bug? Or am I missing something?

Minimized HTML attributes

Currently, if you pass in a numerical-keyed attribute, it will assume the key and value are the same. For example:

echo Form::select('choices', $choices, [ 'class' => 'foo', 'multiple' , 'required'] );

This will render with overly verbose attributes which are redundant, especially especially in HTML5.

<select name="choices" id="choices" class="foo" multiple="multiple" required="required">
...
</select>

Could the HtmlBuilder::attributeElement() method be modified so that numerically-keyed attributes just return a minimized (i.e. value-less) attribute? Maybe something like:

protected function attributeElement($key, $value)
{
    // For numeric keys we will assume that the value is the key and the attribute is
    // to be minimized.  This will render attributes like "required" or "multiple" correctly, 
    // instead of using numerics.
    if (is_numeric($key)) return $value;

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

This would then render as the smaller (and still valid):

<select name="choices" id="choices" class="foo" multiple required>
...
</select>

Problem form binding radio inputs

In the below I would expect it to select the Any option but instead it selects the Closed one.

{!! Form::model(['status' => '']) !!}
    {!! Form::radio('status', '') !!} Any
    {!! Form::radio('status', 'Open') !!} Open
    {!! Form::radio('status', 'Closed') !!} Closed
{!! Form::close() !!}

This is due to a non strict type check on https://github.com/LaravelCollective/html/blob/5.1/src/FormBuilder.php#L792

It's essentially doing '' == 0 which returns true, so selects the 'Closed' option.

Do you think empty strings should be handled explicitly?

M:M relation rendered with checkboxes not correctly autofilled

HOW TO REPRODUCE BUG:
I have an m:m relation in my isolated form.
This relation si rendered by a list of checkboxes.
Checkboxes names are in the form form_name[relation_name][]

BUG:
Form checkboxes autofill functionalities works well only when:

  1. On new form (method=get)
  2. On posting some errors

ERROR:
On edit form data the autofill functionalities wont' work because $posted is a Collection.

date field not formatted when using Form::model()

Hi,

I'm using date mutators in a model passed to Form::model(). Unfortunately the date is not formatted to the Y-m-d form, because the formatting is performed only on the DateTime object passed directly to the date() function. Maybe this code should be placed in the getValueAttribute() function with additional check on the field type? Or there is a better place?

placeholderOption must set empty value

if not set a value attribute then submit a inner tag.

 < return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
 ---
 > return '<option' . $this->html->attributes($options) . ' value="">' . e($display) . '</option>';

Why do default value is prefered to model value ?

When having a value defined in old input it will take precedence over default value, sounds logical.

But when having a value defined in the model, default value will take precedence over model value, I don't understand that, isn't default value intended to be used when there is no other value available ? (in the model or the old input)

Why do default value is prefered to model value ?

Did i do something the wrong way ? ("1" is the default value here) :
{!! Form::number('field_name', 1, ['class' => 'form-control']) !!}

I fix'd it this way, but that's ugly, I must had misunderstood something :
{!! Form::number('field_name', (!empty($model) && $model->field_name !== null)?$model->field_name:1, ['class' => 'form-control']) !!}

Code formatting

There is no code formatting convention in this packages. This is a real issue because it complicates merges (I experienced that this morning), it produces useless diffs (see this one : 9c4fea1) and it gives a bad example to newcomers about our quality standards.

There are files indented with 2 spaces, 4 spaces or tabs. Sometimes a mix of two of this options.

I suggest to use the Laravel 5.1 convention : PSR-2. At least, the indentation should be harmonized ! I think that this should be done in 5.1 and master branches (they are very close).

I can do it if you have not time for that but I wait for your go for now.

HTML::ul

It's expected to implement HTML::ul, like in Laravel 4?

Form::number() does not exist.

Hi,

I'm getting the following exception when I try to use the Form::number() method:

exception 'BadMethodCallException' with message 'Method number does not exist.'
in vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:87

Although the documentation mentions this method, I couldn't find the implementation in the source.

after updating to 5.1.6 checkbox model value not showing

Hi, maybe i'm doing something wrong, but after update to 5.1.6 (from 5.1.4) checkbox will not be checked if model value is '1'...

Form::model($mymodel ...)
Form::checkbox('field','1',false)

any other way to set checbox to checked if value is ==1 ?
tnx

Select, relationships and lists

I'm using the FormBuilder and have a select named the same thing as one of my model's relationships (a many-to-many relationship), but when using form model binding, it ignores any attempts I make to manually override the status of whether it's selected or not.

{!! Form::select('usergroups[]', $groups, $user->groups->lists('id'), array('multiple' => 'multiple') !!}

Doing this, I would expect it a select with some selected values, depending my relationship piece. Instead, no select is selected.

This is User model relationship:

public function groups()
{
    return $this->belongsToMany('SSHAM\Usergroup');
}

And this my controller wich calls the view:

public function edit(User $user)
{
    // Get all existing user groups
    $groups = Usergroup::lists('name', 'id');
    return view('user.edit', compact('user', 'groups'));
}

And my view:

{!! Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'put']) !!}
{!! Form::select('usergroups[]', $groups, $user->groups->lists('id'), array('multiple' => 'multiple') !!}
{!! Form::close() !!}

Am I missing something about how to get this to work or have I stumbled across an issue?

Checkboxes and relationships

I'm using the FormBuilder and have a checkbox named the same thing as one of my model's relationships (a many-to-many relationship), but when using form model binding, it ignores any attempts I make to manually override the status of whether it's checked or not.

{!! Form::checkbox('tags[]', $id, (in_array($id, $articleTags)) !!} {{ $tag }}

Doing this, I would expect it to ignore the relationship piece (which is tries to handle, albeit unsuccessfully, behind the scenes) and instead, use the logic I put in there. Instead, every checkbox is checked, even if I put false in the third parameter.

Am I missing something about how to get this to work or have I stumbled across an issue?

Providing a route name to Form::open does not automatically specify the _method for me

If I have the route:

Route::put('cart/add', ['as' => 'cart.add', 'uses' => 'CartController@addProduct']);

and in a view I have:

{!! Form::open(['route' => 'cart.add']) !!}

I expect the output:

<form method="POST" action="http://localhost:8000/cart/add" accept-charset="UTF-8">
<input name="_method" type="hidden" value="PUT">
<input name="_token" type="hidden" value="wL3...">

But it does not create the _method hidden field. It should detect that the route is a PUT, and automatically output the _method hidden field.

This should work for every non-POST route: GET, PUT, PATCH, DELETE.

Backwards compatibility shouldn't be an issue, as if people have named routes that aren't POST they're already creating their own _method field which will override the one Form::open would create.

Is this something that would be accepted as a pull request?

Easier way to add an empty option in a select element

Continuing from this discussion, I believe it would be worthwhile to have an easier way to include an empty top option in a select field. It can be a pain to have to prepend it to a Collection manually (figuring out how to preserve keys) before passing it to Form::select, while I do believe this is a common use-case. Many dropdowns do not have anything selected by default, after all, so it would be nice if there were no hurdles to overcome to get this functionality.

What could be the best way to fix this? If not through a new option on Form::select, perhaps with a new built-in macro?

Larvel creating html section

laravel 5 it start to showing blank white page after adding 'Collective\Html\HtmlServiceProvider' in provider and 'Form' => 'Collective\Html\FormFacade','Html' => 'Collective\Html\HtmlFacade' for using form tag,I have update the composer successfully .Im working linux (mint).Thanks in advance.

Fresh 5.1+ installation - Class 'Collective\Html\HtmlServiceProvider' not found

Hi,

I made a fresh laravel 5.1+ installtion via laravel new and did the steps required for this package (composer, providers, aliases).

=>

[Symfony\Component\Debug\Exception\FatalErrorException]  
Class 'Collective\Html\HtmlServiceProvider' not found  

Composer require section:

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "laravelcollective/html": "5.1.*"
},

Any guesses?

Updating composer file

While updating composer it shows Call to undefined method Illuminate\Foundat
ion\Application::getCachedCompilePath() in /var/www/laravel-project/vendor/
laravel/framework/src/Illuminate/Foundation/Console/ClearCompiledCommand.ph
p on line 28 .Working on linux fresh install .

No placeholder displayed on select

Hello team,
I'm having an issue with Form::select as no placeholder is displayed while it is correctly set up in my blade (exactly copy-pasted from 5.1 doc). Does anyone encounter this problem?

Below a piece of code of my blade + my app configuration and my composer installed components:

I am using Laravel 5.1.

Form blade:
{!! Form::model($advert, ['route' => ['cms.adverts.update', $advert->id], 'method' => 'put', 'class' => 'form-horizontal panel', 'files' => true]) !!}

{!! Form::select('size', array('L' => 'Large', 'S' => 'Small'), null, ['placeholder' => 'Pick a size...']) !!}

{!! Form::submit('Edit', ['class' => 'btn btn-primary pull-right']) !!}
{!! Form::close() !!}

Config:

env('APP_DEBUG', true), 'url' => 'http://localhost', 'timezone' => 'Europe/Rome', 'locale' => 'it', 'fallback_locale' => 'en', 'key' => env('APP_KEY', 'fooKey'), 'cipher' => 'fooCypher', 'log' => 'single', 'providers' => [ Illuminate\Foundation\Providers\ArtisanServiceProvider::class, Illuminate\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Illuminate\Bus\BusServiceProvider::class, Illuminate\Cache\CacheServiceProvider::class, Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, Illuminate\Routing\ControllerServiceProvider::class, Illuminate\Cookie\CookieServiceProvider::class, Illuminate\Database\DatabaseServiceProvider::class, Illuminate\Encryption\EncryptionServiceProvider::class, Illuminate\Filesystem\FilesystemServiceProvider::class, Illuminate\Foundation\Providers\FoundationServiceProvider::class, Illuminate\Hashing\HashServiceProvider::class, Illuminate\Mail\MailServiceProvider::class, Illuminate\Pagination\PaginationServiceProvider::class, Illuminate\Pipeline\PipelineServiceProvider::class, Illuminate\Queue\QueueServiceProvider::class, Illuminate\Redis\RedisServiceProvider::class, Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, Illuminate\Session\SessionServiceProvider::class, Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, App\Providers\AppServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Collective\Html\HtmlServiceProvider::class, Intervention\Image\ImageServiceProvider::class, ], 'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, 'Blade' => Illuminate\Support\Facades\Blade::class, 'Bus' => Illuminate\Support\Facades\Bus::class, 'Cache' => Illuminate\Support\Facades\Cache::class, 'Config' => Illuminate\Support\Facades\Config::class, 'Cookie' => Illuminate\Support\Facades\Cookie::class, 'Crypt' => Illuminate\Support\Facades\Crypt::class, 'DB' => Illuminate\Support\Facades\DB::class, 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 'Event' => Illuminate\Support\Facades\Event::class, 'File' => Illuminate\Support\Facades\File::class, 'Form' => Collective\Html\FormFacade::class, 'Hash' => Illuminate\Support\Facades\Hash::class, 'Html' => Collective\Html\HtmlFacade::class, 'Image' => Intervention\Image\Facades\Image::class, 'Input' => Illuminate\Support\Facades\Input::class, 'Inspiring' => Illuminate\Foundation\Inspiring::class, 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, 'Password' => Illuminate\Support\Facades\Password::class, 'Queue' => Illuminate\Support\Facades\Queue::class, 'Redirect' => Illuminate\Support\Facades\Redirect::class, 'Redis' => Illuminate\Support\Facades\Redis::class, 'Request' => Illuminate\Support\Facades\Request::class, 'Response' => Illuminate\Support\Facades\Response::class, 'Route' => Illuminate\Support\Facades\Route::class, 'Schema' => Illuminate\Support\Facades\Schema::class, 'Session' => Illuminate\Support\Facades\Session::class, 'Storage' => Illuminate\Support\Facades\Storage::class, 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, ], ]; Output from composer show --installed: classpreloader/classpreloader 2.0.0 Helps class loading performanc... danielstjules/stringy 1.9.0 A string manipulation library ... dnoegel/php-xdg-base-dir 0.1 implementation of xdg base dir... doctrine/inflector v1.0.1 Common String Manipulations wi... doctrine/instantiator 1.0.5 A small, lightweight utility t... fzaninotto/faker v1.5.0 Faker is a PHP library that ge... guzzlehttp/psr7 1.1.0 PSR-7 message implementation hamcrest/hamcrest-php v1.2.2 This is the PHP port of Hamcre... intervention/image 2.3.1 Image handling and manipulatio... jakub-onderka/php-console-color 0.1 jakub-onderka/php-console-highlighter v0.3.2 jeremeamia/SuperClosure 2.1.0 Serialize Closure objects, inc... laravel/framework v5.1.7 The Laravel Framework. laravelcollective/html v5.1.2 league/flysystem 1.0.9 Filesystem abstraction: Many f... mockery/mockery 0.9.4 Mockery is a simple yet flexib... monolog/monolog 1.15.0 Sends your logs to files, sock... mtdowling/cron-expression v1.0.4 CRON for PHP: Calculate the ne... nesbot/carbon 1.20.0 A simple API extension for Dat... nikic/php-parser v1.4.0 A PHP parser written in PHP phpdocumentor/reflection-docblock 2.0.4 phpspec/php-diff v1.0.2 A comprehensive library for ge... phpspec/phpspec 2.2.1 Specification-oriented BDD fra... phpspec/prophecy v1.4.1 Highly opinionated mocking fra... phpunit/php-code-coverage 2.1.8 Library that provides collecti... phpunit/php-file-iterator 1.4.0 FilterIterator implementation ... phpunit/php-text-template 1.2.1 Simple template engine. phpunit/php-timer 1.0.6 Utility class for timing phpunit/php-token-stream 1.4.3 Wrapper around PHP's tokenizer... phpunit/phpunit 4.7.7 The PHP Unit Testing framework. phpunit/phpunit-mock-objects 2.3.5 Mock Object library for PHPUnit psr/http-message 1.0 Common interface for HTTP mess... psr/log 1.0.0 Common interface for logging l... psy/psysh v0.5.2 An interactive shell for moder... sebastian/comparator 1.1.1 Provides the functionality to ... sebastian/diff 1.3.0 Diff implementation sebastian/environment 1.2.2 Provides functionality to hand... sebastian/exporter 1.2.0 Provides the functionality to ... sebastian/global-state 1.0.0 Snapshotting of global state sebastian/recursion-context 1.0.0 Provides functionality to recu... sebastian/version 1.0.6 Library that helps with managi... swiftmailer/swiftmailer v5.4.1 Swiftmailer, free feature-rich... symfony/console v2.7.2 Symfony Console Component symfony/css-selector v2.7.2 Symfony CssSelector Component symfony/debug v2.7.2 Symfony Debug Component symfony/dom-crawler v2.7.2 Symfony DomCrawler Component symfony/event-dispatcher v2.7.2 Symfony EventDispatcher Component symfony/finder v2.7.2 Symfony Finder Component symfony/http-foundation v2.7.2 Symfony HttpFoundation Component symfony/http-kernel v2.7.2 Symfony HttpKernel Component symfony/process v2.7.2 Symfony Process Component symfony/routing v2.7.2 Symfony Routing Component symfony/translation v2.7.2 Symfony Translation Component symfony/var-dumper v2.7.2 Symfony mechanism for explorin... symfony/yaml v2.7.2 Symfony Yaml Component vlucas/phpdotenv v1.1.1 Loads environment variables fr... Extract from my composer.json: ....... "require": { "php": ">=5.5.9", "laravel/framework": "5.1._", "laravelcollective/html": "5.1._", "intervention/image": "^2.3" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.*", "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1" }, ....... Can someone help me or indicate me what I am doing wrong? Thanks for your help in advance, CDF

Select to check selected values from a collection

Hello, i'm using FormBuilder to add a couple of select elements

This select fields are tied to a model relation.

Currently i workaround this with a custom attribute to retrieve the selected elements from the relation and converting them to an array so https://github.com/LaravelCollective/html/blob/5.1/src/FormBuilder.php#L660 can read this options.

I'm thinking of adding a pull request for this to be taken care on the same method to allow for collections to be interpreted directly on the model.

IE.

    if(is_array($selected))
    {
      return in_array($value, $selected) ? 'selected' : null;
    }
    elseif($selected instanceof Collection)
    {
      return $selected->contains('id', $value) ? 'selected' : null;
    }

The problem is that a many-to-many relation should be indexed by the 'id' field following laravel convention, but might be a case where the id actually calls ie. "company_id", in this case the 'id' field would be hardcoded on the condition.

My final issue is should i add this pull request or this should be handled by developers on their own models or views? Is this an issue to someone else or does this have enough support?

Thanks

HTML helps documentation

Under Forms and HTML, in the documentation (readme) for this section, there's no mention of the HTML helpers that the package supports. Or I missed something.

Can't overwrite form field value on model binding

The following doesn't work: (text field has not TEST value)

{!! Form::model($page, array('method'=>'PATCH', 'files'=>true, 'route' => array( 'admin.pages.update', $page->id ) )) !!}
        {!! Form::text('parent_text','TEST',array('class'=>'form-control parent')) !!}
{!! Form::close() !!}

Seems that second field parameter is ignored if old input is present. Weird behaviour as in L4 you could keep old input passing null, or overwrite it passing a value.

Detect HTTP method/verb from routes

Let's say i've got a route definition:

Route::put('users/{user_id}/update', ['as' => 'users.update']);

In order to make a form that submits to that route, i have to do:

echo Form::open(['route' => ['users.update', $user->id], 'method' => 'put']);

It seems strange having to specify the http method in Form::open, when the route definition already has that information. The same is true of controller actions - they both refer to a route definition that has method and url information.

It would be nice to just be able to give the route name:

echo Form::open(['route' => ['users.update', $user->id]]);

With regards to implementation, I've got an idea - i'll PR it.

Test in Laravel 5.1

Hi,

We know Laravel 5.1 has not been released yet. But, is there way to install this package in laravel 5.1 (dev-develop version). Or can you create a new branch for Laravel 5.1?

HTML helper documentation for dropdown menues

In the "Labels" section there is reference to how to create additional HTML attributes.

In the Drop-down-lists section it would be clearer to mention that there must be a default value before an array for HTML attributes (even if null).

i.e. echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');

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

I want to send multiple values to my controller, but when I use:

{!! Form::select('course_phases[]', $phases, null, ['class' => 'form-control', 'multiple']); !!}

or

{!! Form::text('course_phases[]', null, ['class' => 'form-control', 'multiple']); !!}

I'm getting this exception

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

Then I switched to illuminate/html with no changes on my view and works fine, what I'm doing wrong with this package?

EDIT: Forget it, my problem was a javascript outside my form with an input text embbeded, don't know yet how happened!

getModelValueAttribute not loads the appropriate model value when using field names that has the model as other core attribute

Sorry for my english, I hope you will understand :)

Exact issue:
I named a field in database as "visible".
Eloquent model has a protected attribute with same name: protected $visible = [];

When form builder tries to get this field value from model instance, it returns this protected attribute, instead of the data field.

  protected function getModelValueAttribute($name)
  {
if ($name=='visible') dd(data_get($this->model, $this->transformKey($name))); // returns array(0) instead of "1" or "0".
    return data_get($this->model, $this->transformKey($name));
  }

It's because the core eloquent model has ArrayAccess interface.
The data_get helper function runs into this case:

......
            } elseif ($target instanceof ArrayAccess) {
                [DEBUG HERE]
                if (! isset($target[$segment])) {
                    return value($default);
                }
....

DEBUG:
d($target['visible']) => array(0)
d($target->visible) => 1 (correct database value)
When I dump entire $target, the model instance is fine, and the visible attribute too.

Probably would be the same with guarded, fillable, etc fields.

method call: {!! Form::radio('visible', 1) !!}

Maybe this was the same issue: #64

Thanks

Facade Conflict

Hi there,

I maintain Bootstrapper and someone's recently raised patricktalmadge/bootstrapper#279 which leads to our code conflicting since we typehint the Illuminate version of the components. We're still supporting Laravel 4 for a few more months (probably waiting until Twitter Bootstrap v4.0.0 and/or our cross framework project is completed).

Would it be possible for you to add an extra binding (say, collective::html) so that we can use the Laravel 5 version in the meantime? I'm happy to do some real work on compatibility fixing our code if there are issues in illuminate/html that are resolved in this fork that I'm unaware of but I'd like to avoid it if I can

{{ }} not working properly in Laravel 5

As far as i understood {{ }} == echo, but when using it with a Form::select in Laravel 5 it just doesn't work, it prints to screen the html code, but when using <?php echo Form::select ... ?>

Html::image() class not found but Form::image() works. but why?

Before this, I used laravel illuminate/html with the Html::image() tag and it worked fine. This package doesn't seem to support the Html::image() because when I try to use Html::image(), the view return an error and complains that: 'Class 'HTML' not found'

I can use Form::image() with LaravelCollective/html and it works perfetcly but, Form::image() is not what I want because it generates form input instead of a displaying a normal image on the view. For example:

 {!! Form::image('image/icons/like.png','success', array( 'width' => 32, 'height' => 32 ))  !!}

is actually this:

 <input width="32" height="32" src="http://testdomain.com/images/icons/like.png" name="success" type="image">

Of course the disadvantage is that you will have a clickable icon on the image.

I have declared the following allias in the app.php
'Html' => Collective\Html\HtmlFacade::class,

It seems like there is no example either in the documentation how to use Html::image(). Does it exist? Should I install illuminate/html and remove the laravelcollective html facade? Please suggest, not sure if this is just a bug.

Lumen compatibility

This package can also be compatible with Lumen framework.

What I did to make it work:

  1. removed "illuminate/routing": "~5.0", from composer.json (it is not required)
  2. changed "use Illuminate\Routing\UrlGenerator;" to "use Laravel\Lumen\Routing\UrlGenerator;" in HtmlBuilder.php and FormBuilder.php
  3. registered it with "$app->register('Collective\Html\HtmlServiceProvider');" in bootstrap/app.php
  4. added facade bindings in bootstrap/app.php:
    class_alias('Collective\Html\FormFacade', 'Form');
    class_alias('Collective\Html\HtmlFacade', 'Html');

Seems to work fine.
It would be great to have compatibility with Lumen out of the box!

[L5.1] Is this the best way to use Autofocus ?

Hello, I'm trying to use autofocus with partial form.

Did I do the right thing ? Or it has an easy way to do this ?

{!! Form::text('firstname', isset($user->firstname) ? $user->firstname : '', ['autofocus' => '']) !!}

Thanks.

--- Edit ---

I added js to autofocus end of the text.

{!! Form::text('tax', isset($config->tax) ? $config->tax : '', ['autofocus' => '', 'onfocus' => 'this.value = this.value;']) !!}

Error with form model binding on a field named 'visible'

When I hava a table with two columns active tinyint(1) and visible tinyint(1) and try to populate a form with model binding the active field displays correctly and the visible field stays empty.

When I changed out {!! Form::checkbox('visible', true) !!} for {!! Form::text('visible'']) !!} I get an error:ErrorException in helpers.php line 454: htmlentities() expects parameter 1 to be string, array given formed in: HtmlBuilder->attributes(array('class' => 'form-control', 'required', 'name' => 'visible', 'type' => 'text', 'value' => array(), 'id' => null)) in FormBuilder.php line 248

I think it might use the protected property of the Eloquent Model?

The workaround I used for now was to cast the Eloquent result to an array and then back to an object:

$user = $User::find(1);
$user = (object) $user->toArray();

Mutiple radio same id

Form::radio('foo', '1');
Form::radio('foo', '2');

Html =>
<input name="foo" type="radio" value='1" id="foo">
<input name="foo" type="radio" value='2" id="foo">

Why must add an "id"? In addition, the "id" must be unique…

Laravel 5.1 + LaravelCollective HTML and Form = Forms broken

Using Laravel 5.0 with this library used to work fine, but now since I had to upgrade to Laravel 5.1, the library seems to be malfunctioning. I've also installed the 5.1 version of this html/form library too.

Here's how to replicate this:

  • Setup a new project and install the LaravelCollective HTML and Form farcades.
  • Make a blade file with this code:
{!! Form:open([ url => 'foo/bar' ]) !!}
{!! Form:close !!}
  • Set up a view to make that file.
  • Launch the development server and go to the url with that view. Open the debugger (I use Chrome).
  • Look at the HTML source. You'll see this:
<form method="POST" action="">
  • The action part should be what was specified in the 'url' argument. Unfortunately, it gets tossed aside.

Looking at the code, I did see it could possibly have been renamed to 'action' from 'url', but trying that does nothing different. The forms just want to post back to the route they were called from.

A timely resolution would be appreciated.

Unwanted Question Mark

{!! link_to_route('users.index', 'Users') !!}

Is resulting in

url.com/users?

There should be no extra question mark at the end of the URL

HTML tags inside Anchor tag

I need to create link which will contain not only plain text, but icon in addition, what is a best approach to make it?

{!! link_to('/home', '<i class="fa fa-home"></i> Main page') !!}

Using this way symbols < and > decoded and icon isn't displaying because of it.

Thanks.

Cannot pass multiple route parameters to Form::open

It seems you cannot do the following..

{!! Form::model($model, ['route' => ['my.named.route', [$id, $other]]]) !!}

..but sometimes you need to pass in more than one parameter to the named route, even if it's just GET variables

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.