custom input types

#2 · closed · 1 comments

View on GitHub ↗

HellPat

I'd like to add custom input types like "email". I didn't find out how to accomplish this. Any tips?

Comments

raftalks

You can do it very easily in three different ways. Choose any of the following. Method A: Simply call the type attribute after $form->text() ``` php Form::make(function($form)){ $form->text($fieldName, $label)->type('email'); }); ``` Method B: Use the macro option to create your own input types. ``` php Form::macro('input_email', function($name, $label, $value=null, $attr = array()) { return Form::template(function($form) use ($name, $label, $attr, $value) { $form->text($name)->placeholder($label)->value($value)->type('email')->setAttributes($attr); }); }); /** To use the new macro input type **/ Form::make(function($form)) { $form->input_email($fieldName, $fieldLabel, $value); // which should make input type with email }); ``` Method C: The last way to do this, is to hack the code here https://github.com/raftalks/Form/blob/master/src/Raftalks/Form/Html/HtmlMaker.php#L8 to include array key "email" with value "input".