, (*1)
Form component allows you to easily create HTML forms., (*2)
Installation
composer require flextype-components/form
Usage
use Flextype\Component\Form\Form;
Registers a custom macro., (*3)
// Registering a Form macro
Form::macro('my_field', function() {
return '<input type="text" name="my_field">';
});
// Calling a custom Form macro
echo Form::my_field();
// Registering a Form macro with parameters
Form::macro('my_field', function($value = '') {
return '<input type="text" name="my_field" value="'.$value.'">';
});
// Calling a custom Form macro with parameters
echo Form::my_field('Flextype');
Create an opening HTML form tag., (*4)
// Form will submit back to the current page using POST
echo Form::open();
// Form will submit to 'search' using GET
echo Form::open('search', array('method' => 'get'));
// When "file" inputs are present, you must include the "enctype"
echo Form::open(null, array('enctype' => 'multipart/form-data'));
Create a form input.
Text is default input type., (*5)
echo Form::input('username', $username);
Create a hidden form input., (*6)
echo Form::hidden('user_id', $user_id);
Creates a password form input., (*7)
echo Form::password('password');
Creates a file upload form input., (*8)
echo Form::file('image');
Creates a checkbox form input., (*9)
echo Form::checkbox('i_am_not_a_robot');
Creates a radio form input., (*10)
echo Form::radio('i_am_not_a_robot');
Creates a textarea form input., (*11)
echo Form::textarea('text', $text);
Creates a select form input., (*12)
echo Form::select('themes', array('default', 'classic', 'modern'));
Creates a submit form input., (*13)
echo Form::submit('save', 'Save');
Creates a button form input., (*14)
echo Form::button('save', 'Save Profile', array('type' => 'submit'));
Creates a form label., (*15)
echo Form::label('username', 'Username');
Create closing form tag., (*16)
echo Form::close();
License
See LICENSE, (*17)