cbatista8a/formbuilder

1.2.0 2023-02-02 21:26 UTC

This package is auto-updated.

Last update: 2024-09-03 13:32:26 UTC


README

Simple POO Form Builder for PHP projects

Getting Started

These instructions will give you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Installing

clone repo from GitHub

git clone https://github.com/cbatista8a/formbuilder.git

or

composer require cbatista8a/formbuilder

use autoload

require_once './vendor/autoload.php';

Create the Form Object and add some elements and attributes

$form = new FormBuilder();
$form->addAttribute(new Attribute('id','form-test'))
 ->addAttribute(new Attribute('action','example.php'))
 ->addAttribute(new Attribute('class','form-group'))
 ->extractObjectFields($model,'model-group','row')
 ->addElement(new Button('submit','Save'),'form-footer');

If your are ready, just render the HTML and enjoy

echo $form->build();

Element is an abstract class and it's the parent of all other HTML Tags

Input is a basic element of any HTML Form, this is an example of its implementation:

class Input extends Element
{

    private string $type;

    public function __construct(string $type)
    {
        $this->type = $type;
    }

    /**
     * @return string
     */
    public function getType(): string
    {
        return $this->type;
    }

    public function render(): string
    {
        return "<input type='{$this->type}'
                   {$this->renderHtmlAttributes()}
                >
        ";
    }
}

Don't implement this basic element, it's already present on this library

Built With Love and

  • PHP
  • composer

Contributing

You are invited to do pull requests and contribute with us.

Versioning

We use Semantic Versioning

Authors

  • Carlos Batista

License

This project is licensed under the MIT License - see the LICENSE.md file for details.