Download the PHP package moon250/form-generator without Composer
On this page you can find all versions of the php package moon250/form-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moon250/form-generator
More information about moon250/form-generator
Files in moon250/form-generator
Package form-generator
Short Description FormGenerator is a class that generates forms in a very simple way.
License MIT
Informations about the package form-generator
FormGenerator
FormGenerator is a class that generates forms in a very simple way.
Table of contents
- Installation
- Basic usage
- Types
- Options
- Configuration
- Configuration Rules
- empty_generated_field
- form_action
- form_class
- form_method
- form_submit
- form_submit_value
- full_html_structure
- type_detection
- Examples
Installation
You can use composer for install this package.
Basic Usage
Start by instancing the FormGenerator class.
Next, you can use this object to add some fields with the "add" method. This method took 2 parameters, one is the name, and the second parameter is for define the type. This parameter is optionnaly. The default type is text.
To generate the form, use the "generate" method
Types
By default, the type is "text". You can change this by pass another parameter in the "add" method.
If the name of your field ends with "_at", the type of this field will be "date".
If the name specified is a valid type and no type was specified in parameters, the name will be used in type.
Options
In the third parameter of the "add" method, you can pass an array of options.
All the options are list here :
Option name | Usage | Value |
---|---|---|
class | Define the class of the field | string A class name |
label | Define the label for the field | string The label content |
placeholder | Define placeholder of the field | string The placeholder |
required | Define if the field is required | bool true / false (default to true) |
value | You can define the value of the field here | string The value of the field |
Example :
Configuration
Form-generator is fully configurable. You can for example disable the type detection with the name.
You can use "get" method to see the value of a key
Key names are case-insensitive.
You can also pass an array to the FormConfig constructor for define config rules.
Config Rules
All the config rules can be changed are listed here :
Rule Name | Default value | Values can be attributed |
---|---|---|
empty_generated_field | true | bool true / false |
form_action | null | string The route / file form action |
form_class | null | string A class name |
form_method | POST | string GET / POST (for now) |
form_submit | false | bool true / false |
form_submit_value | null | string A value |
full_html_structure | false | bool true / false |
type_detection | true | bool true / false |
empty_generated_field
This config rule will remove in-memory field when the "generate" method is call. Default value is "true".
form_action
With this rule, you can define the action of the <form>
.
Default value is "null".
Note : This rule has no effect if the "full_html_structure" rule is not on "true" value.
form_class
With this rule, you can define the class of the <form>
.
Default value is "null".
Note : This rule has no effect if the "full_html_structure" rule is not on "true" value.
form_method
Set the method of the form. Default value is "POST".
Note : This rule has no effect if the "full_html_structure" rule is not on "true" value.
form_submit
Define if the form contains a "submit" input or not. Default is "true".
Note : This rule has no effect if the "full_html_structure" rule is not on "true" value.
form_submit_value
Set the value of the "submit" input. Default value is "null".
Note : This rule has no effect if the "full_html_structure" and "form_submit" rules are not on "true" value.
full_html_structure
When this rule is activate, the "generate" method will return entire html form structure. Default value is "false".
type_detection
With this rule, if the name is a correct form type, it will be used for the type.
Examples
Making a login form using bootstrap template.