Originally developed by Raymond Irving (15-Dec-2004)
Version 1.3 - 1.4 extended by: Jelle Jager (TobyL) September 2006
Captcha image support - thanks to Djamoer
Multi checkbox, radio, select support - thanks to Djamoer
Styles (for these docs) 'borrowed' from Adam Crownoble's QuickEdit
eForm converts a web form into an email which can be sent via email to specified users. Its main features are: html form mail with attachments, auto-respond, report generation using placeholders and extended form validation.
You can see a more extensive version history here.
eForm is very flexible and there's quite a collection of parameters you can use to get eForm to do what you want. Read some of the examples if you're unsure what to do.
<input type="hidden" name="formid" value="formName" />
or (from eForm 1.4.x) you can set the the id in the form tag itself:
<form id="formName"...>
;&tpl
plus [+fieldname+], where fieldname stands for the name of each form field you wish to include.&email
but for Cc:&email
but for Bcc:&to
parameter. This selector field will act like a numeric
index to select an email. It will start at 1 for the first email
and ends at N for the last email in the list.&to =`sales@me.com,support@me.com,billing@me.com`
&mailselector
=`topic`
&to
parameter. This email address will be the address used to send the email to.[.firstname.]
&tpl
&thankyou
[!eForm &sessionVars=`jobID` ... !]
and
<input type="hidden" value="[+jobID+]" />
&sessionVars
. Normally session variables will overide posted values. By setting &postOverides=`1` posted values will take precedence.&thankyou
parameter is set). Values can be a document id (numeric), chunk name or (relative or absolute) url to css file. Multiple values can be separated by a comma (in fact all three values can be mixed).[!eForm &cssStyle=`assets/site/forms.css,chunkName` ... !]
[!eForm &cssStyle=`chunkName` ... !]
[!eForm &cssStyle=`http://mysite.com/assets/styles/forms.css` ... !]
<style type="text/css">/*some styles*/</style>
<link href="assets/site/forms.css" rel="stylesheet" type="text/css">
assets/site/forms.css,assets/site/more.css,assets/site/gone_overboard.css
&cssStyle
but for adding javascript to the <head> of the page document. Currently Javascript is only added when the form is displayed. &protectSubmit
.Possible values are 0 (off), 1 (all 'required' fields are used) or you can set a comma separated list of field names. To ensure that the session variable works separatedly for different forms the session variable name is based on &formid
({formid}_hash).
&submitLimit
minutes irrespective of the form data. When used in combination with &protectSubmit
submitLimit
takes precedence, meaning that when the time limit has expired the form can be submitted again regardless of the setting of &protectSubmit
(it will unset the session variable). As with &protectSubmit
this parameter uses a session variable with a variable name based on &formid.
&requiredClass
is added to the beginning of any classes already set.
&snipFolder=`eform/1.4.4`
. The value of &snipFolder is added to the basic snippets folder 'assets/snippets/'.It should not include a closing slash (/)!The eForm event functions are now incorporated into the parameters. They are:
[!eForm?
&to=`me@mydomain.com`
&gotoid=`1`
&tpl=`orders`
&report=`orderreport`
!]
[!eForm?
&to=`sales@mysuppliers.com`
&category=`Purchase Order`
&tpl=`chunkPurchaseOrder`
&report=`chunkPurchaseReport`
!]
For all normal form fields eForm automatically inserts appropriate placeholders. However there are a few that you may need to add manually:
[+validationmessage+]
- This should be somewhere in your form template or document. It is used for any validation error messages. From 1.4.2 the way the placehloder is entered has changed. Firstly you no longer need to place it in the form template. You can now place it anywhere in your document (or even in the global page template). Secondly you don't need to place any hml tags around the placeholder (in fact you probably should not). Any html markup is now included in the $_lang['ef_validation_message']
variable in the eform language files (which you can change as required).[+vericode+]
& [+verimageurl+]
- These are needed in the form if you want to use the CAPTHCA code. See the Examples on how to use these.[+postdate+]
- This placeholder can be used in reports and in the thankyou template and will be filled with the current date and time (date on the server that is)[+debug+]
- From version 1.4.1 this is automatically placed (if debug is on) in the form and thankyou template. It is not automatically placed in the report template! This is to avoid any server side information to accidentally be sent out via email. If you need debug info in test emails you will have to add this placeholder in the report template yourself.eForm is incorporating a form parser which extracts formatting and validation options from each form field. To set options for a field add the eform
(pseudo) attribute to each required form field.
<input type="text" name="color" eform="A Color:string:1" />
The basic format of the eform attribute is:
[description/title]:[datatype]:[required]:[validation message]:[validation rule]
You only need to set the following data types. Others will be set automatically (radio & checkbox as they are, string for textbox and listbox for select)
Standard validation: All fields that are required will be checked if they are left empty.
The listbox, checkbox and radio fields do normally not require the datatype to be set. eForm will recognize these automatically. It will validate the values against the list of values placed in the form.
This version instroduces extended server validation and word filtering using very flexible validation rules that can be set in the eform
attribute. You can set 2 extra validation parameters, a custom error message and a validation or filter rule.
example:
eform="Year of Birth:integer:1:Must be between 1950 and 2002:#RANGE 1950-2002"
#LIST blue,red,green.maroon
#RANGE 1,3,-5~-15,60~82
{DBASE}
{PREFIX}
tags which will be replaced by the MODx database name and table prefix respectively.#SELECT keyword FROM {PREFIX}site_keywords
#FUNCTION myValidationFunction
#REGEX /^[a-z]+ [a-z0-9_]+/i
#FILTER #LIST badword,verybadword||goodword,verygoodword
#FILTER #EVAL return myFilterFunction($value);
function myFilterFunction($value){
$badWords = array('scribble','coding');
$goodWords = array('design','sleep');
return str_replace($badWords,$goodWords,$value);
}
Select boxes, radio options and checkbox fields now have working automatic validation. Any input for these fields is validated against the values set in your form template. This avoids anyone tampering with the form by adding their own values to these fields
By default hidden fields are validated as a protection against tampering by comparing the input against the value set in the form template (much like the select, checkbox and radio fields) In some circumstances this may not be desirable however. For instance when you use some javascript in your form to store a result in a hidden field. In those cases you can turn this behaviour off by setting the eform attribute (with or without it's own validation).
Hidden field example 1.
The default behaviour is handy for instance if you are storing a document id and want to be sure
no one can tamper with the id. the field would look like this:
<input type="hidden" name="docId" value="31" />
Hidden field example 2.
Suppose you have a form where a javascript calculated value is stored in a hidden field. To avoid the hidden
field being validated at all you add the following eform attribute:
<input type="hidden" name="calculatedField" value="" eform="::0::" />
Hidden field example 3.
Same scenario as 2 but suppose you want to make sure a value is returned and that it stays within a certain
range. The eform attribute is set with: title,integer data type, required field, error message
and validation with #RANGE (in this example a value between 1-10)
<input type="hidden" name="calculatedField" value="" eform="Calculated Value:integer:1:Calculation out of range:#RANGE 1-10" />
1. Selectbox - set as required field (no validation required)
2. Textbox - required and format set to date
3. Multiple checkbox - required, eform_options only set once.