Home Pass optional parameters to Laravel Form
Reply: 0

Pass optional parameters to Laravel Form

user1343 Published in April 26, 2018, 1:41 pm

This is an excerpt from my partials/textfield.blade.php snippet:

{{ Form::text('mylabel', 'mytext', ['class' =>'form-control']) }}

I know that it's possible to include this snippet and pass some variables to it:

@INCLUDE('partials/textfield', ['required' => 'required', 'autofocus' => 'autofocus'])

I want to be able to call the snippet with optional parameters for required, autofocusand readonly.

My question now is: How can I pass these variables to the form element?

I tried:

{{ Form::text('label',null,
    'class' =>'form-control', 
    'required'  => (isset($required)  ? $required  : 'false'),
    'readonly'  => (isset($readonly)  ? $readonly  : 'false'), 
    'autofocus' => (isset($autofocus) ? $autofocus : 'false') 

This leads to HTML code like ... readonly="false".... The presence of readonly, however, leads internet browsers to render the fields as readonly.

Replacing 'false'with ''doesn't help either. Does anyone know, how to pass these optional parameters to the snippet instead?

Any help is greatly appreciated!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.919288 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO