To get started with PHP Form Builder you have several entry points according to your preferred approach:
Create your forms by simple drag and drop, then copy and paste the code into your page.
The Drag and drop method is the quickest & easiest way to build your forms.
Create your forms using the PHP functions provided for this purpose, simple, documented and explained throughout this project.
Numerous templates and code examples, the function reference and class documentation are available to help you.
If you're not very comfortable coding in PHP, A detailed step-by-step tutorial is available here: PHP Beginners Guide
All you need is:
If you use an invalid hostname like localhost:3000 the solution is to create an alias.
Don't upload upload all the files and folders on your production server.
PHP Form Builder's package includes the Form Builder itself, the documentation and all the templates.
Documentation and Templates are available online at https://www.phpformbuilder.pro/.
There's no need to upload them on your production server.
In the same way, you can use the online Drag & Drop Form Generator
Add phpformbuilder folder at the root of your project.
Your directory structure should be similar to this :
Minimum required files
If you use any plugin, add its folder & xml file, for example phpformbuilder/plugins/select2
and phpformbuilder/plugins-config/select2.xml
More details about folders, files and required files on production server here: ../index.html#package-structure
Registration
Open phpformbuilder/register.php in your browser, enter your purchase code to activate your copy.
Each purchased license allows to install PHP Form Builder on 2 different domains:
Once you activated your purchase, remove register.php from your production server to avoid any unwanted access.
You need 4 PHP blocks in your page :
</head>
to include css files required by plugins<body></body>
to render your form</body>
to include js files & code required by plugins<?php
/*============================================
= 1st block - the form =
============================================*/
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
session_start();
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
$form = new Form('test-form', 'horizontal', 'novalidate');
$form->addInput('text', 'user-name', '', 'Name :', 'required, placeholder=Name');
$form->addRadio('is-all-ok', 'Yes', 1);
$form->addRadio('is-all-ok', 'No', 0);
$form->printRadioGroup('is-all-ok', 'Is all ok ?', false, 'required');
$form->addBtn('submit', 'submit-btn', 1, 'Send', 'class=btn btn-success');
// iCheck plugin
$form->addPlugin('icheck', 'input', 'default', array('%theme%' => 'square', '%color%' => 'red'));
/*===== End of 1st block ======*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Test Form</title>
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<?php
/*============================================================
= 2nd block - css includes for plugins =
============================================================*/
$form->printIncludes('css');
/*===== End of 2nd block ======*/
?>
</head>
<body>
<h1>My first form</h1>
<?php
/*======================================================================================================
= 3rd block - render the form and the feedback message if the form has been sent =
======================================================================================================*/
if (isset($sent_message)) {
echo $sent_message;
}
$form->render();
/*===== End of 3rd block ======*/
?>
<!-- Latest compiled and minified jQuery -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<?php
/*========================================================================
= 4th block - js includes for plugins and js code (domready) =
========================================================================*/
$form->printIncludes('js');
$form->printJsCode();
/*===== End of 4th block ======*/
?>
</body>
</html>
Add this php block just after include_once [...] . '/phpformbuilder/Form.php';
:
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('test-form') === true) {
// create validator & auto-validate required fields
$validator = Form::validate('test-form');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['test-form'] = $validator->getAllErrors();
} else {
$email_config = array(
'sender_email' => 'contact@my-site.com',
'sender_name' => 'PHP Form Builder',
'recipient_email' => 'recipient-email@my-site.com',
'subject' => 'PHP Form Builder - Test form email',
'filter_values' => 'test-form'
);
$sent_message = Form::sendMail($email_config);
Form::clear('test-form');
}
}
Jeff L. Williams's Mysql class is in database folder.
You'll find all documentation and insert / edit / delete examples here : class-doc.php#database-main
<?php
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
session_start();
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('test-form') === true) {
// create validator & auto-validate required fields
$validator = Form::validate('test-form');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['test-form'] = $validator->getAllErrors();
} else {
$email_config = array(
'sender_email' => 'contact@my-site.com',
'sender_name' => 'PHP Form Builder',
'recipient_email' => 'recipient-email@my-site.com',
'subject' => 'PHP Form Builder - Test form email',
'filter_values' => 'test-form'
);
$sent_message = Form::sendMail($email_config);
Form::clear('test-form');
}
}
$form = new Form('test-form', 'horizontal', 'novalidate');
$form->addInput('text', 'user-name', '', 'Name :', 'required, placeholder=Name');
$form->addRadio('is-all-ok', 'Yes', 1);
$form->addRadio('is-all-ok', 'No', 0);
$form->printRadioGroup('is-all-ok', 'Is all ok ?', false, 'required');
$form->addPlugin('icheck', 'input', 'default', array('%theme%' => 'square', '%color%' => 'red'));
$form->addBtn('submit', 'submit-btn', 1, 'Send', 'class=btn btn-success');
?>
<!DOCTYPE html>
<html>
<head>
<title>Test Form</title>
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<?php $form->printIncludes('css'); ?>
</head>
<body>
<h1>My first form</h1>
<?php
if (isset($sent_message)) {
echo $sent_message;
}
$form->render();
?>
<!-- Latest compiled and minified jQuery -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<?php
$form->printIncludes('js');
$form->printJsCode();
?>
</body>
</html>
Now you've learned the basics ; Several resources will help to add other fields, plugins, validate different values and build more complex layouts :