bewarhizirvan / laravel-form
A Form generator for Laravel
Requires
- php: ^7.1|^7.4|^8.0|^8.1.0
- illuminate/support: ~5|~6|~7|~8|~9
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3|~4
- phpunit/phpunit: ^8.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2024-12-24 08:45:49 UTC
README
This is where your description should go. Take a look at contributing.md to see a to do list.
Installation
Via Composer
$ composer require bewarhizirvan/laravel-form
Usage
For initiating new form
$form = new \BewarHizirvan\LaravelForm\LaravelForm($parameters);
$parameters must be an array and is optional, all keys are optional
title : Form Title
name : Form name
method : Form method { get, post (default), put, patch } class : Form class
role : Form role
dir : Form direction { right, left (default) }
id : Form id
file : if you set a value to it , the Form will have enctype="multipart/form-data"
submit : Form submit button title, if you set it to 'none' it will be removed
back_url : Form Back button URL, if you set it to 'none' it will be removed
For form action One of these you can use {default is ''}
url : Full URL
route : Route { only route string or array Laravel Style }
action : Action { only action string or array Laravel Style }
Functions
$form->addText($name = null, $value = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addFile($name = null, $value = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addButton($label = '', $attributes = []) $form->addHidden($name = null, $value = '', $attributes = []) $form->addSelect($name= null, $options = [], $value='',$attributes = [],$label=null, $label_attributes = [], $div_attributes = []) $form->addTextArea($name = null, $value = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addCheckbox($name = null, $value = 1, $checked = false, $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addCheckboxGroup($name = null, $checkboxes = [], $checked_list = [], $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addRadioGroup($name = null, $radios = [], $checked = '', $attributes = [], $label = null, $label_attributes = [], $div_attributes = []) $form->addTable($label = '', $table_data = [], $label_attributes = [], $table_attributes = [], $thead_attributes = [], $tbody_attributes = [], $tfoot_attributes = [], $div_attributes = [])
For all function if $label = null, the the function will set $label = trans("db.$name")
For addTable function $table_data will be
$table_data = [ 'names' => [], 'inputs' => [], 'sums' => [], 'buttons' => [], ];
When finished do bellow
$form = $form->render();
the above step will generate an html code
Example form
$form = new \BewarHizirvan\LaravelForm\LaravelForm($parameters); $form->addText('email'); $form->addText('name'); $form->addText('password', '', ['type' => 'password']); $form = $form ->render();
Static Function
\BewarHizirvan\LaravelForm\LaravelForm::redirect($route = '/');
The above function will check the $request for back_url, if it is set it will redirect to it else it will redirect to the provided route
Change log
Please see the changelog for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see contributing.md for details and a todolist.
Credits
License
MIT. Please see the license file for more information.