Quickstart

Requirements

If your webserver supports PHP7, simply download the HazzelForm folder, extract the zip file and include it anywhere in your web project.

Minimalist configuration

Important:
Make sure you place STEP 1-3 on top of you PHP script before headers or any html content is defined.
// STEP 1: tell your app the location of HazzelForms and initialize the framework
require_once(__DIR__ . '/HazzelForms/autoload.php');
$form = new HazzelForms\HazzelForm();

// STEP 2: add a form field using the parameters 'title', 'type' and an optional parameter list
$form->addField('E-Mail', 'email', ['label' => 'Sign up to our newsletter']);

// STEP 3: send mail if everything is valid
if($form->validate()){
  $form->sendMail('marketing@example.com');
}

// STEP 4: output the complete form html to your website
$form->renderAll();

Initialize form with custom settings

// include HazzelForms
require_once __DIR__ . '/HazzelForms/autoload.php';

// simple
$form = new HazzelForms\HazzelForm();

// example with parameters
$form = new HazzelForms\HazzelForm(array(
	'autocomplete' => 'false',
	'action' => 'yourOwnDataProcessing.php'
));

Attributes

Add optional parameters to change default form settings:

Parameter Type Default Info
action string current URL It is recommended to use default action for proper server-side validation.
method string post Nobody does send a form via get method but it would be possible.
novalidate boolean false Toggle client side validation functionality of browsers
autocomplete boolean true Decide wether browsers should help the users filling out the form.
formname string hazzelform_1 Internal form identifier. The <form> tag will get this ID too. For multiple forms on a page, the default number will be increased
lang string EN HazzelForms uses json formatted language files for the error messages. Check the folder HazzelForms/lang/* to see if HazzelForms already supports your language.
If not, you can easily duplicate and translate / adapt a language file.
With the parameter 'lang' => 'yourlanguage', HazzelForms will look for a file named yourlanguage.json to get the error messages from.
stealthmode boolean false If you switch on stealth mode, HazzelForms won't output the submit button. Furthermore it will ignore error messages and the grid wrapper. You will need javascript to submit the form. This takes effect when $form->renderAll(); is used to create DOM elements.
submitcaption string 'grid-wrap' This parameter allows you to customize the submit button caption when using $form->renderAll(); to create the whole form.
gridclass string 'grid-wrap' This parameter allows you to customize the class of the div which HazzelForms wraps around the form.

Add fields

/**
 *   Add new fields using these parameters:
 *   @param String  $fieldName
 *   @param String  $type
 *   @param Array   $attributes  (optional)
 */

$form->addField('Name', 'text', array('placeholder' => 'Please enter your name',
															        'maxlength'   => 35
                                    ));

Attributes

Every field type has its own field specific parameters.
Please see field types for more information.

Set default value

// get field by name and set its value
$form->getField('Name')->setValue('the value');

Form rendering

Use the following functions to create the html code for your fields, labels and error messages.

// Let HazzelForms do the whole magic
$form->renderAll();
// do things manually
$form->openForm();								 	// open form tag *
$form->openGrid();									// open grid system

$form->openField('fieldName');			// wraps a grid-system box around the field
$form->renderLabel('fieldName');		// show label if defined as field parameter
$form->renderInput('fieldName');   	// create input field *
$form->renderError('fieldName');   	// field specific error message
$form->closeField('fieldName');   	// field wrapper closing tag

$form->renderField('fieldName');   	// render the above 5 (wrapper, label, input tag and error all together)

$form->renderSubmitErrors();				// show general errors
$form->renderSubmit();  				 		// render submit button (required when not submitting via javascript)

$form->closeGrid();									// grid system closing tag
$form->closeForm();   							// form closing tag and hidden fields *

* required