This is the Item Title

by NPetrovich

Short Description

Installation Guide

Uploading files. Upload fast_form_builder.php file, which is located in "item" folder, via FTP client to any place in your project. To know more about using FTP and uploading files follow this link.

Configuring settings. To configure work of Fast Form Builder you need to setup some constants inside the class. To do this open uploaded fast_form_builder.php file with any text editor you are comfortable. Now scroll quick reminder instructions to the class declaration. Here you will see some constants with settings values, setup them as you need, here is the minings:

  • VIEW_LOCATION (string) - path to HTML templates, must be absolute or from fast_form_builder.php file
  • ACTIVATE_LOG (boolean)- logging activation
  • LOG_FILE (string) - path to log file, must be absolute or from fast_form_builder.php file
  • DEFAULT_ACTION (string) - default url inside action attribute of the form tag
  • DEFAULT_SUBMIT (string) - default text of submit button inside value attribute
  • DEFAULT_METHOD (string) - default sending method inside method attribute of the form tag
  • SUBMIT_NAME (string) - default value of submit button inside name attribute

Notice: object using SUBMIT_NAME for internal identification, if you are using more than one form on a single page you need to setup unique values in setting of each form.

Connecting to project. To connect Fast Form Builder class in your project include fast_form_builder.php file in index.php file. Example:

1
include_once('path_to_class_folder/fast_form_builder.php');
copy
source

Form Setup

To setup form you need to create object from FastFormBuilder class and build correct array of configuration settings. All settings of the form are included ind 2nd level array with 'form' key. This is the list of settings:

  • action (string)* - url inside action attribute of the form tag
  • value (string) - text of submit button inside value attribute
  • method (string)* - sending method inside method attribute of the form tag
  • view (string) - url for redefining of HTML template
  • submitname (string)* - value of submit button inside name attribute
  • attributes (array) - array of additional attributes with, where key of array is HTML attribute and value of array is value of HTML attribute

Notice: settings marked with '*' are required, if not setup they will be replaced with default values.
Notice: object using 'submitname' for internal identification, if you are using more than one form on a single page you need to setup unique values in setting of each form.

Example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14
$args = [
    'form' => [
    	'action' => '/index.php',
    	'value' => 'Send It',
        'method' => 'get',
        'view' => 'redefine/',
        'submitname' => 'formid',
    	'attributes' => [
    		'id' => 'form-id',
    		'class' => 'form-class'
    	]
    ]
];
$demo_form = new FastFormBuilder ($args);
copy
source

To output form you need to call 'render' method of the object, and echo it`s return in a place where you want it to appear:

1
echo $demo_form -> render ();
copy
source

Text Input

To add text input in your form you need to add an array, with any key, to configuration for object creation. This is the list of settings:

  • type (string)* - value of the type attribute
  • name (string)* - value of the name attribute
  • label (string) - text notice of a field
  • attributes (array) - array of additional attributes with, where key of array is HTML attribute and value of array is value of HTML attribute

Notice: settings marked with '*' are required, if data setup are incorrect field will not appear, message will be added to log, if it`s active.

Example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
$args = [
    1 => [
        'type' => 'text',
        'name' => 'name',
        'label' => 'test text',
        'attributes' => [
            'id' => 'test-id',
            'class' => 'test-class'
        ]
    ],
    'form' => [
    	'action' => '/index.php',
    	'value' => 'Send It',
        'method' => 'get',
        'view' => 'redefine/',
        'submitname' => 'formid',
    	'attributes' => [
    		'id' => 'form-id',
    		'class' => 'form-class'
    	]
    ]
];
$demo_form = new FastFormBuilder ($args);
copy
source

Textarea

Textarea input can be added to the form in a same way as the input with type 'text'. Difference. You need to setup type value to 'textarea'.

Checkbox

Checkbox input can be added to the form in a same way as the input with type 'text'. Difference. You need to setup type value to 'checkbox' and add a value setting, example:

1 2 3 4 5 6 7 8 9 10 11
...
3 => [
        'type' => 'checkbox',
        'name' => 'ch1',
        'value' => 'box',
        'label' => 'test box',
        'attributes' => [
            'class' => 'test-class'
        ],
    ],
...
copy
source

Radio Button

Radio input can be added to the form in a same way as the input with type 'text'. Difference. You need to setup type value to 'radio' and add a value setting. Also you need to describe each radio button separately. To group radio-boxes get them a same name. Example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
...
4 => [
        'type' => 'radio',
        'name' => 'r1',
        'value' => 'rad',
        'label' => 'radio box 1',
        'attributes' => [
            'class' => 'test-class-47'
        ],
    ],
    5 => [
        'type' => 'radio',
        'name' => 'r1',
        'value' => 'rad2',
        'label' => 'radio box 2',
        'attributes' => [
            'class' => 'test-class-47'
        ],
    ],
...
copy
source

Select

Select can be added to the form in a same way as the input with type 'text'. Difference. You need to setup type value to 'select'. Also you need to add array, with 'list' key, to specify all options. Where key of array is 'value' attribute and value of array is a description of option. Example:

1 2 3 4 5 6 7 8 9 10
...
6 => [
        'type' => 'select',
        'name' => 's',
        'label' => 'my select',
        'list' => [
            'one' => 'One',
            'two' => 'Two',
            'lat' => '3'
        ]
    ],
...

Validation

Class have validation options. To use it you need to setup validation parameters, as an option array with key 'validation', and call validation method from object to pass it form data for validation. Multiple rules can be setup. Method will return boolean true if data is correct and false if not. Error messages will be applied to form automatically.

This is list of available validation rules:

  • require (bool) - input mast be not empty, value 'true'
  • regex (string) - string with regular expression
  • email (bool) - text mast be an e-mail, value 'true'

Example:

1 2 3 4 5 6 7 8 9 10 11 12
...
2 => [
    	'type' => 'textarea',
    	'name' => 'description',
        'label' => 'test area',
        'validation' => [
            'require' => true,
            'regex' => '/(test@test.com)/',
            'email' => true
        ]
    ],
...
copy
source

To enable validation you need to call it before form rendering:

1 2 3
$result = $demo_form -> validation ( $_GET );
if($result) echo 'OK';
else echo 'Error';
copy
source

Get Messages

You can get an array of validation errors by calling 'getValidationResults' method, after 'validation' method:

1
print_r ( $demo_form -> getValidationResults () );
copy
source

File Structure

File Type Description
view Folder Folder with all default templates
=> checkbox.tpl HTML template input default template
=> form.tpl HTML template Main template with form and submit tags
=> radio.tpl HTML template Radio input default template
=> select-option.tpl HTML template Options tag template for select input default template
=> select.tpl HTML template Select input default template
=> text.tpl HTML template Text input default template
=> textarea.tpl HTML template Textarea default template
fast_form_builder.php PHP script Main file with class description

Templates

You can apply your own template for the form by redefining default templates. First create a folder for new templates and setup path to it in 'view' setting for object creation, read 'Form Setup' for more. Than copy needed templates 'tpl' files from default folder to your new one, and edit code ass you need. To define which template do you need read 'File Structure' section.

Notice: select type consist from two templates, read 'File Structure' section for more.

Logging

You can activate logging system to debug or monitor images events on your site. It use next marks of value:

  • Error - wrong functioning of some method.
  • Warning - event which require your attention.
  • Notice - event about which you may be interesting to know.
  • Info - simple event.
  • Debug - event which require code debugging.
To activate the log you need to set ACTIVATE_LOG constant in 'true' position. It is located at the beginning of the class declaration. Also you can assign your own path and name of the log file in the LOG_FILE constant. Example:

1 2 3 4
...
const ACTIVATE_LOG = true;
const LOG_FILE = '/logs/log.txt';
...
copy
source

Render list of log events:

1
echo FastFormBuilder :: showLog("class");
copy
source

Clear log:

1
FastFormBuilder :: deleteLog();
copy
source

Unistallation

Just delete template files, and don`t forget to delete redefined templates if there is. You can check it by reading path to it in 'view' setting for object creation, read 'Form Setup' for more.