jarzon/forms

This package is abandoned and no longer maintained. The author suggests using the jarzon/forms package instead.
There is no license information available for the latest version (v1.32.3) of this package.

Form generator/validator

Maintainers

Details

github.com/Jarzon/Form

Source

Issues

Installs: 32

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 6

Type:project


README

Install

composer require jarzon/form

Usage

Build the form

<?php
$form = new Jarzon\Form($_POST);

// Create your form
$form
  ->text('name')
  ->min(2)
  ->max(100)
  ->required()
  ->placeholder('Joe Doe')

  ->number('age')
  ->min(0)
  ->max(100)
  
  ->submit();

Show the form in the view

<?=$form('form')->html?>

    <div><?=$form('name')->label('Name:')->row?></div>
    
    <div><?=$form('age')->label('Age:')->row?></div>
    
    <?=$form('submit')->value('Save')->html?>

<?=$form('/form')->html?>

Process the form values

<?php
// On submit validate the form values
if($form->submitted()) {
    try {
        // Does the validation based on the inputs types, min/max, required
        if($values = $form->validation()) {
            // Do what you want with the returned values
            echo "Your name is {$values['name']}";
        }
    }
    catch (\Jarzon\Form\ValidationException $e) {
        // ->validation() throw a custom Exception if there is an invalid value
        echo "Error: {$e->getMessage()}";
    }
}