hakimch/form

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple PHP form generator class for PHP 5.6+.

v1.0.1 2016-02-26 00:13 UTC

This package is auto-updated.

Last update: 2023-05-08 06:20:26 UTC


README

A simple html form generator class Code Climate SensioLabsInsight Build Status Scrutinizer Code Quality Build Status

Install via composer

composer require 'hakimch/form'

Initialize the form

$form = HakimCh\Form\Form::init();
$form->setup(
    $datas, // Submited datas
    $token, // If you want add csrf token (require CSRF class)
    $action // Current url for action attribute
);
echo $form->addAttr([
                'id' => 'Form', // Adding attr Id
                'class' => 'formClass', // adding a class
                'enctype' => 'multipart/form-data' // If you want use it for upload some files
           ])->open();

// you can add fields here

echo $form->close(); // Closing form

Add text field

You can add many field type as (text,password,date,time,file,hidden,textarea)

// Create label(name, for, required)
// Required arg will add <span class="required">*</span>
echo $form->addAttr('for', firstName')->label('firstName', true);
// A normal text field with a name
echo $form->text('firstName');

// Add an Advanced text field with options
echo $form->addAttr([
        'id' => 'secondName',
        'value' => 'Chmimo',
        'class' => 'required greenColor'
      ]) // add attrs by passing an array
      ->text('secondName');
// Add a textarea
echo $form->addAttr('rows',5) // add number of rows
      ->addAttr('class','redBorder') // adding a class name
      ->textarea('about');

Add a select

It accept 2 args (name, options) options as an array with key => value

echo $form->select('record', [1, 2, 3]);

Add box field

Radio field

echo $form->addAttr('value',1)->radio('testRadio', 'Radio 1');
echo $form->addAttr('value',2)->radio('testRadio', 'Radio 2');

Checkbox field

echo $form->addAttr('value',1)->checkbox('testCheckbox[]', 'Checkbox 1');
echo $form->addAttr('value',2)->checkbox('testCheckbox[]', 'Checkbox 2');

Add submit button

// Accept one arg (value)
echo $form->addAttr('class', 'btn btn-success')->submit('Send my Form');

#License (MIT License)

Copyright (c) 2012-2015 Hakim Chmimo ab.chmimo@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.