Building a Laravel form without Illuminate/html

Laravel 5 version got us confused by separating our beloved Form::open world into a separate package. Now you have to add “illuminate/html”: “~5.0” to your projects, whenever you want to use forms, right? Not necessary, you can survive without it.

How we would build a simple form with that package:

{!! Form::open(array('url' => 'admin/cities')) !!}
  City name:
  
{!! Form::text('title', old('title')) !!}
{!! Form::submit('Save') !!} {!! Form::close() !!}

Now, how it looks if we build it in plain Laravel/HTML:

{{ csrf_field() }} City name:

It’s not that bad, is it? The only thing we need to take differently is take care of CSRF protection, which is basically done with method csrf_field().

Another example would be a DELETE form – here we need to use two additional methods.

{{ csrf_field() }} {{ method_field('DELETE') }}

As you can see, function method_field() is used for adding a hidden field like this:


Then Laravel mechanism would point that form to the correct Controller method delete().

So, the question remains open: do we really need that external illuminate/html Form functionality? Not always. Probably, depends on your skills – which would give you faster results – and on your particular usage in your application.

Which one do you prefer? Do yo use that package? Tell your experience in comments.

Like our articles?
Check out our Laravel online courses!

9 COMMENTS

  1. I use Form::model, too. How would one accomplish an edit form with out the package? Also, I use Form::label, which can obviously be replaced with straight HTML. Finally, why aren’t you escaping old(‘title’)? You have {!! not {{

  2. Sir, I have a question about mail sending.
    How can I send mail to localhost/xampp to gmail?
    should I change php.ini from xampp or not?
    if I should not, then what i have to do for sending mail?
    please , tell me elaborately

  3. From L4. I am very shocked by this change. It is absurd!! EVERYONE uses HTML::style and HTML::link. Furthermore, EVERYONE uses HTML::Form unless you are making a kindergarten web page.

  4. Thank you for this, have been looking all over for this information. We have not installed the Form package and it’s hard to find examples without it.

LEAVE A REPLY

Please enter your comment!
Please enter your name here