devinci-it / quick-form
Quick-Form is a lightweight PHP library designed to streamline the creation of HTML forms in your PHP applications. It provides a simple and intuitive interface for generating HTML forms with ease.
README
The Devinci\QuickForm
library provides a convenient way to generate HTML forms dynamically in PHP applications. With this library, developers can easily create and customize forms with various input types, set form attributes, and handle form rendering seamlessly.
Features
- FormBuilder Class: The core component of the library, allowing for the programmatic creation of HTML forms.
- Support for Multiple Input Types: Text inputs, integer inputs, text areas, date inputs, radio buttons, and checkboxes are all supported.
- Form Attribute Management: Easily set form attributes such as method, action, class, and id.
- Input Grouping: Group input fields together for better organization and presentation within the form.
- Submit and Clear Buttons: Set submit and clear buttons with customizable attributes.
- Customization: Flexibility to customize form elements, attributes, and buttons according to requirements.
Installation
You can install the Devinci\QuickForm
library via Composer:
composer require devinci-it/quick-form
Alternatively, you can include the necessary files manually in your project.
Usage
-
Instantiate FormBuilder: Create an instance of the
FormBuilder
class by providing the form action and, optionally, the form submission method and a custom HTML renderer.$formBuilder = new FormBuilder('/submit-form', 'POST');
-
Set Form Attributes: Optionally, set attributes for the form tag using the
setFormAttributes
method.$formBuilder->setFormAttributes([ 'class' => 'my-form', 'id' => 'my-form-id' ]);
-
Add Input Fields: Add input fields to the form using methods like
addTextInput
,addIntegerInput
,addTextArea
, etc.$formBuilder->addTextInput('username', 'Enter your username', ['class' => 'form-control']); $formBuilder->addIntegerInput('age', 'Enter your age');
-
Group Inputs: Group input fields together using the
setInputGroup
method if needed.$formBuilder->setInputGroup('personal_info', ['username', 'age']);
-
Set Submit and Clear Buttons: Set the submit button and clear button using the
setSubmitButton
andsetClearButton
methods respectively.$formBuilder->setSubmitButton('submit', 'Submit Form', ['class' => 'btn btn-primary']); $formBuilder->setClearButton('clear', 'Clear Form', ['class' => 'btn btn-secondary']);
-
Render the Form: Render the form HTML using the
render
method.echo $formBuilder->render();
-
Integration with Web Applications: Integrate the generated forms seamlessly into your web applications by embedding them within HTML pages or templates.
-
Customization: Customize the appearance and behavior of forms by modifying CSS styles, JavaScript interactions, and form processing logic as per your application's requirements.
Examples
The Devinci QuickForm library can be used for various use cases including:
- User Registration Forms
- Data Entry Forms
- Contact Forms
- Survey Forms
Contribution
Contributions to the Devinci QuickForm library are welcome! Feel free to submit bug reports, feature requests, or pull requests via GitHub.
License
This library is licensed under the MIT License. See the LICENSE file for details.