1. Go to this page and download the library: Download assegaiphp/forms library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
assegaiphp / forms example snippets
use Assegai\Forms\Form;
use Assegai\Forms\Enumerations\HttpMethod;
$form = new Form(
method: HttpMethod::POST,
selector: '#contact-form'
);
if ($form->isSubmitted()) {
// Validate the form
$form->validate();
if ($form->isValid()) {
// Process the form data
$data = $form->getData();
// ...
} else {
$errors = $form->getErrors();
// Handle validation errors
}
}
echo $form->render();
use Assegai\Forms\Form;
use Assegai\Forms\Enumerations\HttpMethod;
use Assegai\Forms\FormControls\TextField;
$form = new Form(method: HttpMethod::POST, selector: '#user-form');
// Create a field with validation rules
$nameField = new TextField('name', '', ['
// Get data as an associative array
$data = $form->getData();
// Get data as a stdClass object
$dataObject = $form->getData(asObject: true);
// Check if a field exists
if ($form->has('name')) {
// Get a specific field value
$name = $form->getFieldValue('name');
// Get the field object
$nameField = $form->getField('name');
// Remove a field
$form->removeField('name');
}
use Assegai\Forms\Enumerations\HttpMethod;
// POST forms
$postForm = new Form(method: HttpMethod::POST, selector: '#form');
// GET forms
$getForm = new Form(method: HttpMethod::GET, selector: '#search');
// PUT/PATCH forms for updates
$updateForm = new Form(method: HttpMethod::PUT, selector: '#update-form');
$patchForm = new Form(method: HttpMethod::PATCH, selector: '#patch-form');
// Set the form ID
$form = new Form(selector: '#my-form');
// Set the form CSS classes
$form = new Form(selector: '.form-class1.form-class2');
// Set the form action URL
$form = new Form(selector: '/submit-form');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.