Without PHP Form Builder, your page loads the plugin dependencies (CSS and Javascript files) one by one.
If your form uses 5 plugins, you will need to call at least 10 files (5 CSS + 5 Javascript), which considerably increases the loading time.
PHP Form Builder groups and compresses all the CSS and Javascript dependencies into a single CSS | Javascript file.
Your page will therefore only call 2 dependency files. Efficiency is maximum, no matter how many plugins you use.
Javascript dependencies can also be loaded with the excellent loadjs library.
PHP Form Builder Options are defining HTML wrappers and classes.
Default options are Bootstrap 4 options.
Each can be overwritten the way you want to match other framework
For example, with Bootstrap, each group (label + element) has to be wrapped into a <div class="form-group"></div> and to have a .form-control class
We also need do add .col-sm-x & .control-label to labels, and to wrap elements with <div class="col-sm-x"></div>.
All will be easily done with Form options.
if needeed, wrappers can contain 2 html elements.
This can be done with elementsWrapper, checkboxWrapper and radioWrapper.
// required markup is automaticaly added on required fields
<label>my required text<sup class="text-danger"> *</sup></label>
openDomReady (if not using jQuery, changes the code your plugins will be wrapped in)
$(document).ready(function() {
closeDomReady
});
Customizing for other framework
If you want to use PHP Form Builder with another framework like Semantic-UI, Pure, Skeleton, UIKit, Milligram, Susy, Bulma, Kube, ..., you have to change the options to match your framework HTML & CSS classes:
$options = array(
// your options here
);
$form->setOptions($options);
If you always use the same framework, the best way is to create a custom function with your custom config in FormExtended class.
/**
* Defines the layout (horizontal | vertical | inline).
* Default is 'horizontal'
* Clears values from session if self::clear has been called before
* Catches posted errors
* Adds hidden field with form ID
* Sets elements wrappers
*
* @param string $form_ID The ID of the form
* @param string $layout (Optional) Can be 'horizontal', 'vertical' or 'inline'
* @param string $attr (Optional) Can be any HTML input attribute or js event EXCEPT class
* (class is defined in layout param).
* attributes must be listed separated with commas.
* Example : novalidate,onclick=alert(\'clicked\');
* @param string $framework (Optional) bs3 | bs4 | material | foundation
* (Bootstrap 3, Bootstrap 4, Material design, Foundation >= 6.4)
* @return $this
*/
options
Call setOptions() only if you change defaults options
/**
* Sets form layout options to match your framework
* @param array $user_options (Optional) An associative array containing the
* options names as keys and values as data.
*/
Mode (production vs. development)
Default mode is production.
$form->setMode($mode);
/**
* set the form mode to 'development' or 'production'
* in production mode, all the plugins dependencies are combined and compressed in a single css or js file.
* the css | js files are saved in plugins/min/css and plugins/min/js folders.
* these 2 folders have to be wrirable (chmod 0755+)
* @param string $mode 'development' | 'production'
* @return $this
*/
Call setAction() only if you change default action
$form->setAction($url, [$add_get_vars = true]);
/**
* Redefines form action
*
* @param boolean $add_get_vars (Optional) if $add_get_vars is set to false,
* url vars will be removed from destination page.
* Example: www.myUrl.php?var=value => www.myUrl.php
*/
Start Fieldset
Start your fieldset with optional legend.
Don't forget to call endFieldset to end your fieldset.
/**
* Starts a fieldset tag.
* @param string $legend (Optional) Legend of the fieldset.
* @param string $fieldset_attr (Optional) Fieldset attributes.
* @param string $legend_attr (Optional) Legend attributes.
*/
End Fieldset
$form->endFieldset();
/**
* Ends a fieldset tag.
*/
startDependentFields
Start a dependent fields block.
dependent fields block is hidden and will be shown if $parent_field changes to one of $show_values.
Don't forget to call endDependentFields to end your Dependent Fields block.
if $inverse is true, dependent fields will be shown if any other value than $show_values is selected
Each Dependent fields block can include one or several dependent fields blocks.
Dependent fields MUST NOT START with the same fieldname as their parent field.
/**
* Start a hidden block
* which can contain any element and html
* Hiden block will be shown on $parent_field change
* if $parent_field value matches one of $show_values
* @param string $parent_field name of the field which will trigger show/hide
* @param string $show_values single value or comma separated values which will trigger show.
* @param boolean $inverse if true, dependent fields will be shown if any other value than $show_values is selected.
* @return void
*/
/**
* Adds input to the form
*
* @param string $type Accepts all input html5 types except checkbox and radio:
* button, color, date, datetime, datetime-local,
* email, file, hidden, image, month, number, password,
* range, reset, search, submit, tel, text, time, url, week
* @param string $name The input name
* @param string $value (Optional) The input default value
* @param string $label (Optional) The input label
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the input.
* Example: class=my-class,placeholder=My Text,onclick=alert(\'clicked\');
*/
Input Groups
Input Groups allow to have several inputs / selects on the same line in horizontal forms.
Up to 12 elements can be grouped.
2 ways to set arguments:
// 1st way: each fieldname as argument
$form->groupInputs('street', 'zip', 'countries');
// 2nd way: a single array including all fieldnames as argument
$fields = array('street', 'zip', 'countries');
$form->groupInputs($fields);
Always create your input group BEFORE creating the input elements.
/**
* Allows to group inputs in the same wrapper
*
* Arguments can be:
* - a single array with fieldnames to group
* OR
* - fieldnames given as string
*
* @param string|array $input1 The name of the first input of the group
* OR
* array including all fieldnames
*
* @param string $input2 The name of the second input of the group
* @param string $input3 [optional] The name of the third input of the group
* @param string $input4 [optional] The name of the fourth input of the group
* @param string ...etc.
*/
/**
* Adds textarea to the form
* @param string $name The textarea name
* @param string $value (Optional) The textarea default value
* @param string $label (Optional) The textarea label
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the textarea.
* Example: cols=30, rows=4;.
*/
Options for Select list
Always add your options BEFORE creating the select element
/**
* Adds option to the $select_name element
*
* @param string $select_name The name of the select element
* @param string $value The option value
* @param string $txt The text that will be displayed
* @param string $group_name (Optional) the optgroup name
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the option.
* Example: class=my-class
*/
Just add selectpicker class for Bootstrap select or select2 class for Select2 plugin, data-attributes and phpformbuilder will do the job..
Don't forget to activate your plugins to add the required css/js files to your page.
/**
* Adds a select element
*
* IMPORTANT: Always add your options BEFORE creating the select element
*
* @param string $select_name The name of the select element
* @param string $label (Optional) The select label
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the input.
* Example: class=my-class
* @param string $displayGroupLabels (Optional) True or false.
* Default is true.
*/
/**
* adds a country select list with flags
* @param array $select_name
* @param string $label (Optional) The select label
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the input.
* Example: class=my-class
* @param array $user_options (Optional):
* lang : MUST correspond to one subfolder of [PLUGINS_DIR]countries/country-list/country/cldr/
* *** for example 'en', or 'fr_FR' Default: 'en'
* flags : true or false. Default: true
* *** displays flags into option list
* flag_size : 16 or 32 Default: 32
* return_value : 'name' or 'code' Default: 'name'
* *** type of the value that will be returned
* show_tick : true or false
* *** shows a checkmark beside selected options Default: true
* live_search : true or false Default: true
*/
/**
* Adds radio button to $group_name element
*
* @param string $group_name The radio button groupname
* @param string $label The radio button label
* @param string $value The radio button value
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* Example: checked=checked
*/
/**
* Prints radio buttons group.
*
* @param string $group_name The radio button group name
* @param string $label (Optional) The radio buttons group label
* @param string $inline (Optional) True or false.
* Default is true.
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the input.
* Example: class=my-class
*/
/**
* Adds checkbox to $group_name
*
* @param string $group_name The checkbox groupname (will be converted to an array of indexed value)
* @param string $label The checkbox label
* @param string $value The checkbox value
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* Example: checked=checked
*/
/**
* Prints checkbox group.
*
* @param string $var (Optional) description
*
* @param string $group_name The checkbox button group name
* @param string $label (Optional) The checkbox group label
* @param string $inline (Optional) True or false.
* Default is true.
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the input.
* Example: class=my-class
*/
/**
* Adds button to the form
*
* If $btnGroupName is empty, the button will be automaticaly displayed.
* Otherwise, you'll have to call printBtnGroup to display your btnGroup.
*
* @param string $type The html button type
* @param string $name The button name
* @param string $value The button value
* @param string $text The button text
* @param string $attr (Optional) Can be any HTML input attribute or js event.
* attributes must be listed separated with commas.
* If you don't specify any ID as attr, the ID will be the name of the input.
* Example: class=my-class,onclick=alert(\'clicked\');
* @param string $btnGroupName (Optional) If you want to group several buttons, group them then call printBtnGroup.
*
*/
Print Btn Group
$form->printBtnGroup($btnGroupName);
/**
* Prints buttons group.
*
* @param string $btnGroupName The buttons group name
* @param string $label (Optional) The buttons group label
*
*/
/**
* Adds HTML code at any place of the form
*
* @param string $html The html code to add.
* @param string $element_name (Optional) If not empty, the html code will be inserted.
* just before or after the element.
* @param string $pos (Optional) If $element_name is not empty, defines the position
* of the inserted html code.
* Values can be 'before' or 'after'.
*/
When your HTML is linked to an element, always call addHtml() BEFORE creating the element
To add helper texts icons buttons or any input group addon it'll be even better to use the shortcut functions:
/**
* Wraps the element with html code.
*
* @param string $html The html code to wrap the element with.
* The html tag must be opened and closed.
* Example: <div class="my-class"></div>
* @param string $element_name The form element to wrap.
*/
Set $debug to true if you wants to display HTML code
Set $display to false if you wants to return HTML code but not display on page
$form->render([$debug = false, $display = true]);
/**
* Renders the html code of the form.
*
* @param boolean $debug (Optional) True or false.
* If true, the html code will be displayed
* @param boolean $display (Optional) True or false.
* If false, the html code will be returned but not displayed.
*
*/
Ajax loading
PHP Form Builder allows you to load your forms with Ajax.
Loading in Ajax allows to:
integrate your forms in any html page
load the forms asynchronously, which is good for your page loading speed
To load your form with Ajax:
1
Create your form using the built-in PHP functions and save it in a php file somewhere on your server. Set the ajax option to true to enable Ajax loading. Here's a sample code:
<?php
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
/* =============================================
start session and include form class
============================================= */
$form_id = 'my-form';
session_start();
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
/* =============================================
validation if posted
============================================= */
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken($form_id) === true) {
// do stuff
}
/* ==================================================
The Form
================================================== */
$form = new Form($form_id, 'horizontal', 'data-fv-no-icon=true, novalidate');
// $form->setMode('development');
// enable Ajax loading
$form->setOptions(['ajax' => true]);
// add your fields & plugins here
// render the form
$form->render();
2
In your main file (html): Create a div with a specific id, for instance:
<div id="ajax-form"></div>
3
In your main file (html):
Add the Javascript code to load your form:
<script>
var $head= document.getElementsByTagName('head')[0],
target = '#ajax-form'; // replace with the id of your div
var loadData = function(data, index) {
if (index <= $(data).length) {
var that = $(data).get(index);
if ($(that).is('script')) {
// output script
var script = document.createElement('script');
script.type = 'text/javascript';
if (that.src != '') {
script.src = that.src;
script.onload = function() {
loadData(data, index + 1);
};
$head.append(script);
} else {
script.text = that.text;
$('body').append(script);
loadData(data, index + 1);
}
} else {
// output form html
$(target).append($(that));
loadData(data, index + 1);
}
} else {
$.holdReady(false);
}
};
$(document).ready(function() {
$.ajax({
url: 'ajax-forms/contact-form-1.php', // replace with the url of your php form
type: 'GET'
}).done(function(data) {
$.holdReady(true);
loadData(data, 0);
}).fail(function(data, statut, error) {
console.log(error);
});
});
</script>
/**
* Prints html code to include css or js dependancies required by plugins.
* i.e.:
* <link rel="stylesheet" ... />
* <script src="..."></script>
*
* @param string $type value : 'css' or 'js'
* @param boolean $debug (Optional) True or false.
* If true, the html code will be displayed
* @param boolean $display (Optional) True or false.
* If false, the html code will be returned but not displayed.
* @param boolean $combine_and_compress (Optional) True or false.
* If true, dependancies are combined and compressed into plugins/min/ folder.
* @return $this
*/
About optimization
PHP Form Builder is conceived for maximum optimization and extremely fast loading time.
$form->addInput('text', 'my-colorpicker', '', 'ColorPicker: ');
$form->addPlugin('colorpicker', '#my-colorpicker');
// call this just before </head>
$form->printIncludes('css');
$form->addInput('text', 'my-colorpicker', '', 'ColorPicker: ');
$form->addPlugin('colorpicker', '#my-colorpicker');
// call this just before </body>
$form->printIncludes('js');
If your form contains no plugin, no need to call this function.
$form->printJsCode($debug = false);
/**
* Prints js code generated by plugins.
* @param boolean $debug (Optional) True or false.
* If true, the html code will be displayed
* @param boolean $display (Optional) True or false.
* If false, the html code will be returned but not displayed.
*/
addHelper() MUST always be called BEFORE creating the element
/**
* Shortcut to add element helper text
*
* @param string $helper_text The helper text or html to add.
* @param string $element_name the helper text will be inserted just after the element.
*/
Example
$form->addHelper('Enter your last name', 'last-name');
$form->addInput('text', 'last-name', '', 'Last name', 'required');
Add Addon
Adds button or text addon before or after the chosen field
$form->addAddon($input_name, $addon_html, $pos);
/**
* shortcut to prepend or append button or text addon to an input
* @param string $input_name the name of target input
* @param string $addon_html button or text addon html code
* @param string $pos before | after
*/
/**
* shortcut to prepend or append icon to an input
* @param string $input_name the name of target input
* @param string $icon_html icon html code
* @param string $pos before | after
*/
PHP Form Builder manages the memorization of fields and posted values without you needing to take any action.
If your form is posted with errors (validation fails), the posted values are automatically displayed in the corresponding fields.
To set the default value of a field, it must be saved in the PHP session in this way:
$_SESSION['form-id']['field-name'] = 'my-value';
If the form is posted, the field will have the posted value. Otherwise it will have the default value registered in the PHP session.
Here's the global workflow:
You create your form and add fields.
PHP Form Builder registers each field name in PHP session: $_SESSION['form-id']['fields'][] = 'field-name';
You post the form
You validate the posted values: $validator = Form::validate('form-id');
If the validation fails:
The error messages are stored in PHP session: $_SESSION['errors'][$form_ID] as $field => $message
You instanciate your form again:
PHP Form Builder registers the posted values in PHP session: $_SESSION['form-id']['field-name'] = $_POST['my-value'];
PHP Form Builder gets and displays the session value and the possible error for each field.
registerValues (static function)
When you instantiate a form, it automatically stores corresponding posted values in session unless you called clear function before creating your form.
Values are registered this way: $_SESSION['form-id']['field-name']
You can call Form::registerValues('form-id') manually at any time.
Form::registerValues('form-id');
/**
* register all posted values in session
* @param string $form_ID
*
* ex: $_SESSION['form-id']['field-name'] = $_POST['field-name'];
*/
mergeValues (static function)
mergeValues is used to merge previously registered values in a single array. Usefull for step forms to send all steps values by email or store into database for example.
/**
* merge previously registered session vars => values of each registered form
* @param array $forms_array array of forms IDs to merge
* @return array pairs of names => values
* ex: $values[$field_name] = $value
*/
clear (static function)
Clears the corresponding previously registered values from session.
Form::clear('form-id');
Validation
Overview
PHP Form Builder comes with 2 distinct validation systems.
PHP Validation Form is validated after being posted. This is a php validation, essential for security.
jQuery Validation Fields are validated on the fly, for better User Experience.
Never forget: The only way to avoid security issues is PHP Validation. Users can easily disable Javascript, and get around jQuery validation.
PHP Validation
Basics
To create a new validator object and auto-validate required fields, use this standard-code (replace 'form-id' with your form ID)
/* =============================================
validation if posted
============================================= */
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('form-id') === true) {
// create validator & auto-validate required fields
$validator = Form::validate('form-id');
// additional validation
$validator->maxLength(100)->validate('message');
$validator->email()->validate('user-email');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['form-id'] = $validator->getAllErrors();
} else {
// validation passed, you can send email or do anything
}
}
$validator = Form::validate('form-id');
This loads Validator class, creates a new Validator object and validate required fields if any. Required fields validation is automatic, nothing more to do.
Then we use $validator native methods for others validations (email, date, length, ...)
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['form-id'] = $validator->getAllErrors();
}
If any error, we register them in session. Error messages will be automatically displayed in form.
Dependent fields validation
Dependent fields validation is something really magic.
Form::validate() validates the required dependent fields only if their parent field value matches the condition to display them.
If you use additional validators, for example $validator->email()->validate('user-email'); you have to test if the field has to be validated or not according to your dependent fields conditions:
if ($_POST['parent-field'] == 'value') {
$validator->email()->validate('user-email');
}
$validator->required()->validate('my-field.0');
/* if at least 2 values must be selected: */
$validator->required()->validate(array('my-field.0', 'my-field.1'));
The field value must be a valid credit card number.
RequiredoneOf($allowed, $message = null)
The field value must be one of the $allowed values. $allowed can be either an array or a comma-separated list of values. If comma separated, do not include spaces unless intended for matching.
RequiredhasLowercase($message = '')
The field value must contain at least 1 lowercase character.
RequiredhasUppercase($message = '')
The field value must contain at least 1 uppercase character.
RequiredhasNumber($message = '')
The field value must contain at least 1 numeric character.
RequiredhasSymbol($message = '')
The field value must contain at least 1 symbol character.
Define your own custom callback validation function. $callback must pass an is_callable() check. $params can be any value, or an array if multiple parameters must be passed.
Required
: Empty fields are NOT VALID
Optional
: Empty fields are VALID
Validation examples
Validation examples code
Main validation code
if ($_SERVER["REQUEST_METHOD"] == "POST" && Form::testToken('my-form-id') === true) {
// create validator & auto-validate required fields
$validator = Form::validate('contact-form-1');
// additional validation
$validator->email()->validate('email-field-name');
// add custom message if you want:
$validator->integer('You must enter a number')->validate('number-field-name');
$validator->captcha('captcha')->validate('captcha-field-name');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['my-form-id'] = $validator->getAllErrors();
}
}
Checkboxes validation
If we want at least one checked:
$form->addCheckbox('chk_group', 'check 1', 1);
$form->addCheckbox('chk_group', 'check 2', 2);
$form->addCheckbox('chk_group', 'check 3', 3);
$form->printCheckboxGroup('chk_group', 'check one: ');
/* Validation: */
if(!isset($_POST['chk_group']) || !is_array($_POST['chk_group'])) {
/* if none posted, we register error */
$validator->required('check at least one checkbox please')->validate('chk_group');
}
Trigger an error manually
If we want at least 2 checked:
$form->addCheckbox('chk_group', 'check 1', 1);
$form->addCheckbox('chk_group', 'check 2', 2);
$form->addCheckbox('chk_group', 'check 3', 3);
$form->printCheckboxGroup('chk_group', 'check at least 2: ');
/* Validation: */
if(!isset($_POST['chk_group']) || !is_array($_POST['chk_group']) || count($_POST['chk_group']) < 2) {
/* if less than 2 posted, we create a tricky validation which always throws an error */
$validator->maxLength(-1, 'Check at least 2 please')->validate('chk_group');
}
To add any custom validation, use HTML5 attributes with validatorname and validator option:
<?php
$form->addInput('text', 'username', 'Username', '', 'data-fv-not-empty, data-fv-not-empty___message=The username is required and cannot be empty');
The callback function allows to enable/disable validators and use the Form Validation plugin API the way you want.
Create a function named fvCallback - The validator plugin will call it as soon as it's ready. Then you can use all the validator API.
The callback function name is fvCallback
The form validator instance can be found this way:
var form = forms['my-form'];
// form.fv is the validator
form.fv.on('core.form.invalid', function() {
// do stuff
});
example of use:
<script type="text/javascript">
var fvCallback = function() {
var form = forms['my-form'];
// form.fv is the validator
// you can then use the formvalidation plugin API
form.fv.on('core.form.invalid', function() {
// do stuff
});
};
</script>
/**
* Send email with posted values and custom content
*
* Tests and secures values to prevent attacks (phpmailer/extras/htmlfilter.php => HTMLFilter)
* Uses custom html/css template and replaces shortcodes - syntax : {fieldname} - in both html/css templates with posted|custom values
* Creates an automatic html table with vars/values - shortcode : {table}
* Merges html/css to inline style with Pelago Emogrifier
* Sends email and catches errors with Phpmailer
* @param array $options
* sender_email : the email of the sender
* sender_name [optional] : the name of the sender
* reply_to_email [optional] : the email for reply
* recipient_email : the email destination(s), separated with commas
* cc [optional] : the email(s) of copies to send, separated with commas
* bcc [optional] : the email(s) of blind copies to send, separated with commas
* subject : The email subject
* isHTML : Send the mail in HTML format or Plain text (default: true)
* textBody : The email body if isHTML is set to false
* attachments [optional] : file(s) to attach : separated with commas, or array (see details inside function)
* template [optional] : name of the html/css template to use in phpformbuilder/mailer/email-templates/
(default: default.html)
* human_readable_labels [optional]: replace '-' ans '_' in labels with spaces if true (default: true)
* values : $_POST
* filter_values [optional] : posted values you don't want to include in the e-mail automatic html table
* custom_replacements [optional] : array to replace shortcodes in email template. ex : array('mytext' => 'Hello !') will replace {mytext} with Hello !
* sent_message [optional] : message to display when email is sent
* debug [optional] : displays sending errors (default: false)
* smtp [optional] : use smtp (default: false)
*
* @param array $smtp_settings
* host : String Specify main and backup SMTP servers - i.e: smtp1.example.com, smtp2.example.com
* smtp_auth: Boolean Enable SMTP authentication
* username: String SMTP username
* password: String SMTP password
* smtp_secure: String Enable TLS encryption. Accepted values: tls|ssl
* port: Number TCP port to connect to (usually 25 or 587)
*
* @return string sent_message
* success or error message to display on the page
*/
The fields named *-token and *submit-btn are automatically filtered. This means that the posted values will not appear in the email sent.
Copy/paste an existing html/css template from phpformbuilder/mailer/email-templates/ and save it into phpformbuilder/mailer/email-templates-custom/ (or create a new html file + a new css file with both same name)
Use the shortcode {table} in your html template if you want to add an automatic html table with all posted values
(And/Or) Put fieldnames between braces in your template. They'll be replaced automatically with posted values. For example: Hello {user-first-name} {user-name}
[optional] You can use the custom_replacements option to replace specific texts in email with specific values
Call sendMail() function and set your html template in template option
How to replace array values using sendMail() function
To replace values posted in array in custom email template, best way is to create non-array indexed values, then add them in sendMail custom_replacements option
Example using array values
<?php
/*
Example with 3 posted colors
Email template will use {color_1}, {color_2}, {color_3}
*/
// create index
$i = 1;
// loop through posted values
foreach ($_POST['color'] as $color) {
// name indexed variable and give it posted value
$var = 'color_' . $i;
$$var = $color;
// increment index
$i++;
}
$options = array(
// [...]
'custom_replacements' => array(
'color_1' => $color_1,
'color_2' => $color_2,
'color_3' => $color_3
),
// [...]
);
$sent_message = Form::sendMail($options);
Your message has been successfully sent !
Attachments Examples
Examples using FileUpload plugin
The upload path is configured in phpformbuilder/plugins/jQuery-File-Upload/server/php/[YourFileUploadHandler].php.
The uploaded filename is sent using hidden field, for example $_POST['files'].