Data is saved into the table “tx_thmailformplus_log” having the following fields:
uid : unique ID of the record
pid : Typo3 pageID from which the form was submitted
submittedfields : data definition plus the values are saved here **
date : the date+time when the record was saved
**... because the form can change (by adding, deleting or renaming an input field) the structure is saved with every record followed by a line break and the data the user submitted.
Example:
id;L;SUBMITTED;name;email;address
400;;1;peter;netdog@typoheads.com;vienna
Tipp:
If you think some fields saved in the log-table are useless or you don't need them, use the TypoScript functionality described in the “Configuring the log-table” chapter:
plugin.tx_thmailformplus_pi1.saveLog.exclude = x,y, id
The “x”,”y” and “id” fields are no longer saved into the log-table anymore after adding this to the TypoScript setup.
New in 3.5.0:
Exported records are marked and not shown anymore in the list of records by default. If you want to see all records (also the ones that have been exported) you have to check the field “show also exported records” in the configuration box.
New in 3.4.0:
added a “raw export” checkbox: check if you don't want the form fieldnames to be exported as first row in the csv file. If there are records stored with different data structures (e.g. you renamed the inputfield “first_name” to “firstName”) you would normally get a alert-message that the exported records have different data structures. Check “raw export” to export the records with no regard to the data structures.
added a “convert UTF-8 to ISO-1” checkbox: If you have configured your Typo3 installation as multilanguage site, the inputfields and the values are also saved in this UTF-8 format. Unfortunately when exporting data as CSV file you cann't tell excel that the CSV file is in UTF-8 format. So check this field if you want the data to be converted into ISO-1 format.
Attention:
If you use checkboxes, the “structure” of each submitted form looks different (depending on how many checkboxes the user has checked).
You can solve the problem by using the TypoScript functionality described in section "Configuring the log-table (csv export via backend module)”.
If you need to save the submitted fields to the Database, please use the TypoScript specifications for that as shown in section “Saving the submitted values into a DB table of your choice”.
When you try to export records that were saved from different forms (meaning the fields in the form were not the same) you will get a warning showing the different definitions.
Still you have the possibility to export records that are based on different forms (but at your own risk). This was done because if you rename a input field from “tel” to “phone”, it makes sense to give you the possibility to download the “old” data saved with the field name “tel” and the “new” data saved with the field name “phone” in one .CSV file.
Attention: if records are deleted, you can not recover the data anymore (it's really deleted from the database!)
To use upload fileds within your form, you have to:
add enctype="multipart/form-data" to your <form ..> tag
configure mailformplus to save the uploaded data into a table of your choice
Please read the next section “saving the submitted values into a DB table of your choice (TS)”.
You will find a working example there as well.
Why do you have to save the submitted data in a DB table to make the fileupload work?
All uploaded files are saved within one folder. Because files would have to be renamed if a file with the same name already exists, problems could occur.
To prevent that problem of filenames and to know who has uploaded which file, we have to generate a unique filename and attach the file to the rest of the submitted data.
A simple way (shown and explained in the next chapter) is, to save the submitted form in the tt_content table (including the link to the picture). The generated unique number (UID) is used within the filename of the uploaded file.
You can define via TS-setup on which page the content element is inserted and if it should be hidden or shown by default (or deleted).
(since 3.1)
This allows you to choose a database table and store all (or some) values submitted via a formular into this table.
Also fileuploads can be handled.
Typoscript support:
plugin.tx_thmailformplus_pi1
saveDB = 1 | 1 ... enable saving to DB 0 ... disable saving to DB (or if not defined) |
saveDB.dbTable | Name ofdatabase table used for saving |
saveDB.fileUpload | optional Directory where the uploaded files (if any) are stored. The file will be renamed to: [pageID]_[FormularInputFieldName]_[createdRecordID].[fileType] Example: uploads/tx_threzepte/ |
saveDB.fileTypes | optional allows only uploaded files of this type. Seperate mulitple types by “,” data will not be saved if the file does not correlate with this types. (use ###error_filetype### placeholder for displaying the error message) Example: jpg,gif,png,jpeg |
saveDB.fileSize | optional this limits the maximum size of one uploaded file – data will not be saved if the file is too large (use ###error_filesize### placeholder for displaying the errormessage) Example: 50000 (50 Kb) |
saveDB.dbinsert | optional inserts given values into the databse. Useful if you want to set the inserted records to “hidden” example: pid:7,hidden:1 |
saveDB.dbkey | Default: uid If you want to insert the records into a table that does not use “uid” as key field. Important because the generated key is taken as part of the filename (if you allow the user to upload a file with the form) |
saveDB.mapping | Not default! You have to specify into which table field the form field is saved. Abstract: [inputFieldName]:[DBName],[inputFieldName]:[DBName],... Example: surename:name,title:title,ingredients:ingredients |
saveDB.debug | ATTENTION: If the extension does not work as expected, set this to 1 to display various debug messages. Do NOT activate this feature on an online page – the messages would be displayed also to the users! |
saveDB.if_is_empty.[fieldname] | optional [fieldname] ... name of formular inputfield If field is not filled out, you can specify a default value which will be used. Example: saveDB.if_is_empty.subscribe = no |
Example:
The following example code can be found in the “example_form/” directory.
This example shows a way to save the submitted fields into tt_content table.
Use this example if you want to save uploaded files.
After upgrading mailformplus to the latest version do the following:
Step 1:
Prepare the HTML-template with the form and insert it on a page as described in the section “Configuration and usage of mailformplus”.
Example template:
<!-- ###TEMPLATE_FORM### begin -->
<form name="Formular" method="post" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="id" value="###PID###">
<input type="hidden" name="submitted" value="1">
<input type="hidden" name="L" value="0">
###ERROR###
<table border="0" cellspacing="2" cellpadding="0">
<tr>
<td valign="top">Name</td>
<td valign="top">###error_name###<input type="text" name="name" value="###value_name###"></td>
</tr>
<tr>
<td valign="top">Subject</td>
<td valign="top">###error_subject###<input type="text" name="subject" value="###value_subject###"></td>
</tr>
<tr>
<td valign="top">e-mail</td>
<td valign="top">###error_email###<input type="text" name="email" value="###value_email###"></td>
</tr>
<tr>
<td valign="top">Phone</td>
<td valign="top">###error_phone###<input type="text" name="phone" value="###value_phone###"></td>
</tr>
<tr>
<td valign="top">Topic</td>
<td valign="top">###error_topic###<select name="topic" style="width:320px;">
<option value="leer" ###selected_topic_leer###></option>
<option value="webdesign" ###selected_topic_webdesign###>Webdesign</option>
<option value="hosting" ###selected_topic_hosting###>Webhosting</option>
<option value="price" ###selected_topic_price###>Price for...</option>
<option value="feedback" ###selected_topic_feedback###>Feedback</option>
</select></td>
</tr>
<tr>
<td valign="top">Text</td>
<td valign="top"><textarea cols="50" rows="5" name="text" style="width:320px;">###value_text###</textarea></td>
</tr>
<tr>
<td valign="top" colspan="2" style="padding-top:2px;padding-bottom:2px;"><br />please contact me via:</td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"><input type="radio" name="contact_via" value="email" style="border-style:none;" ###checked_contact_via_email###>e-mail <input type="radio" name="contact_via" value="phone" style="border-style:none;" ###checked_contact_via_phone###>Phone</td>
</tr>
<tr>
<td valign="top" colspan="2" style="padding-top:2px;padding-bottom:2px;"><br />please send us your photo...</td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top">###error_filesize######error_filetype###<input type="file" name="photo" size="50" maxlength="50000" accept="image"><br>
<input type="file" name="photo2" size="50" maxlength="50000" accept="image"></td>
</tr>
<tr>
<td> </td>
<td valign="top" align="left"><input type="submit" value="submit"></td>
</tr>
</table>
</form>
<!-- ###TEMPLATE_FORM### end -->
<!-- ###TEMPLATE_SUBMITTED_OK### begin
OPTIONAL - will be shown if form was submitted and all required fields were filled out
-->
<b>Thank you, your request will be answered soon.</b>
you have uploaded the following files:<br>
###UPLOAD1###<br>
###UPLOAD2###<br>
<hr>
or:<br>
###photo###<br>
###photo2###
<!-- ###TEMPLATE_SUBMITTED_OK### end -->
<!-- ###TEMPLATE_EMAIL_USER### begin
OPTIONAL - this will be the email text that is sent to the user (plaintext!)
-->
Hello ###name###,
You have just filled out the form and asked about:
###subject###
you uploaded the following files:
###photo###
###photo2###
We will contact you as soon as possible,
ciao!
<!-- ###TEMPLATE_EMAIL_USER### end -->
<!-- ###TEMPLATE_EMAIL_RECEIVER### begin
OPTIONAL - this will be the email text that is sent to the admin (plaintext!)
(admin-email = the email you can specify in the mailformplus plugin)
-->
Hello admin,
A user just filled out the form:
name: ###name###
subject: ###subject###
uploaded files:
###photo###
###photo2###
please contact the user: ###email###
<!-- ###TEMPLATE_EMAIL_RECEIVER### end -->
<!-- ###TEMPLATE_ERROR### begin -->
<!-- ###ERROR_START### begin
this is used for the global error marker ###ERROR### -->
The following errors occured:
<ul>
<!-- ###ERROR_START### end -->
<!-- ###ERROR_END### begin
this is used for the global error marker ###ERROR### -->
</ul>
<!-- ###ERROR_END### end -->
<!-- ###ERROR_FILESIZE### begin
this is used if you use the file upload functionality -->
<li>File is too large!</li>
<!-- ###ERROR_FILESIZE### end -->
<!-- ###ERROR_FILETYPE### begin
this is used if you use the file upload functionality -->
<li>File is not allowed!</li>
<!-- ###ERROR_FILETYPE### end -->
<!-- ###ERROR_name### begin -->
<li>insert Title</li>
<!-- ###ERROR_name### end -->
<!-- ###TEMPLATE_ERROR### end -->
Step 2:
Insert an extension template on the page where you inserted the mailformplus element.
In the “setup” field insert the following:
plugin.tx_thmailformplus_pi1.saveDB = 1
plugin.tx_thmailformplus_pi1.saveDB {dbTable = tt_content
fileUpload = uploads/pics/
fileTypes = jpg,gif,png,jpeg
# set maximum filesize to 100Kb
fileSize = 100000
# change “96” to an existing page-ID in your TYPO3 project
dbinsert=pid:96,hidden:0,CType:textpic
# if dbkey is not set: "uid" is taken
dbkey =uid
# [inputFieldName]:[DBName]
mapping=name:header,subject:bodytext,photo:image,photo2:image
}
That's it! If you submit the form a new content element (text with picture) is created on page 96.
Attention: the created content element is set to visible! If you want to hide it, set “dbinsert=... ,hidden:1,...”
Tips for fileuploads:
In our example the user has the possibility to upload two pictures. Both pictures are stored within one database field “image”. This is done by mapping both formular fields to the same DB-field: “photo:image,photo2:image”
Instead of saving the submitted data into the tt_content table, you could also save it into tt_board (as forum posting) or in tt_address (as FE-user).
The filename of the uploaded files consists of: [pageID]_[formularInputFieldName]_[recordID].[filetype]
With this name you can identify to which page and which content element the picture belongs to.
(since 3.3)
This allows you to specify which fields have to be saved in the log-table and in which order.
Default: all fields submitted (having a value) are saved.
Problem:
When you use checkboxes in your form, a unchecked checkbox won't be saved at all in the log-table. This causes incompatibility in the csv-export-format.
Solution:
Use this typoscript functionality to ensure a fix format for your csv-exports.
Typoscript support:
plugin.tx_thmailformplus_pi1
saveLog = 1 | 1 ... enable customized saving to log-table 0 ... disable customized saving to log-table (or if not defined) default: 0 (all submitted fields having a value are saved) |
saveLog.order | specify formular inputfield names seperated by “,” that should be saved into log-table Attention: fields in log-table are also written in this order |
saveLog.defaultValue | optional default: '' specify the value that should be saved if the user has not filled out the formular field. e.g.: a checkbox is not checked |
saveLog.exclude | specify formular inputfield names seperated by “,” that should NOT be saved into log-table all other fields are saved (since 3.4.0) |
Example:
plugin.tx_thmailformplus_pi1.saveLog = 1
plugin.tx_thmailformplus_pi1.saveLog {order = price,first_name , surename,email,phone,message,freeCD
defaultValue= 0
exclude = x,y, id
}
Attention:
If you use this functionality, all data fields that are submitted but not configured to be saved into the log-table will be lost! (of course, you still have the data in the email that is sent out)
This section is interesting for you if you
want to display a dynamic inputfield defined in TypoScript
want to add additional headers to the emails sent out
plugin.tx_thmailformplus_pi1
emailHeader | optional to send out HTML-emails or emails with UTF-8 encoding the values will be added to the header of all emails that are sent out comment: if you don't specifiy your own charset here, the default character set of the typo3 installation is taken |
emailParameter | optional this string is used when sending the mail via the php mail() function as 5th parameter example: emailParameter = -f automailer@yourdomain.com |
markers | optional syntax: markers.[markername] = [TypoScript] [markername] has to be used within the HTML-template as marker: ###[markername]### see example below |
captchaFieldname | optional Only works if you have the extension “captcha” installed. Set the name of the inputfield where the user types in the text shown on the captcha-picture. example: captchaFieldname = captcha_check |
saveUserFunc | optional Calls an user defined function after the form was submitted successfully. example: saveUserFunc = EXT:myext/class.tx_myext.php:tx_myext->doit See section “Hook for post-processing” for more details. |
saveUserFunc. | optional You can define parameters that will be passed on to the user function called when the form was submitted correctly. example: saveUserFunc.dummy = hello See section “Hook for post-processing” for more details. |
plugin.tx_thmailformplus_pi1.default
These settings match exactly the fields you can fill out in the mailformplus-element. A default setting is only taken if the field in the mailformplus-element is left blank. | |
.email_to | help@mydomain.com Info: That's the email address where the “admin” email is sent to. |
.email_subject | [text] contact form was filled out Info: That's the subject of the admin-email. |
.email_sender | [email] Info: This emailaddress is used as sender in the admin-email. |
.email_redirect | [pageID] 10 Info: PageID where the user gets redirected to when submitting a correct filled out form. |
.email_requiredfields | [fieldnames] used in the form name,email Info: Use fieldnames of the inputfields to enable a server side check if they are filled out. |
.email_requiredfields.wrap | to add required fields dynamicly example: email_requiredfields.wrap = |,subject |
.email_htmltemplate | [path] to html-template ../../fileadmin/forms/contact.html ATTENTION: always use “../../” as prefix! Info: This is the path and the HTML-template file with the form. |
.email_replyto | [fieldname] used in the form Info: Fill in the name of the formular inputfield where the user fills in the email address. This emailaddress is then taken as reply-to address. Clicking on “reply” in your email program to an admin-email lets you send an email directly to the user. |
.email_sendtouser | [fieldname] used in the form user_email Info: If you want a email to be sent to the user who has submitted the form, you have to use the inputfield name where the user puts in his/her emailaddress here. |
.email_subject_user | [text] Thank you for your registration. Info: That's the subject of the email sent to the user. (see “email_sendtouser”) |
examples:
emailHeader:
plugin.tx_thmailformplus_pi1.emailHeader = Content-Type: text/plain; charset="UTF-8"\r\nContent-Transfer-Encoding: 7bit
This sends out UTF-8 encoded emails.
markers:
Let's say you want to have a dropdown filed in a form showing all departments of your company and you want a email to be sent to the head of the department when a user fills out the form and submitts it.
What we need:
a page having the departments as subpages
use the “subtitle” field of the department pages to store the email-addresses for each department.
place a placeholder ###pulldown_departments### in the right place of your HTML-template
... then put this code to your TypoScript setup:
temp.jsmenu = HMENU
temp.jsmenu.special = directory
temp.jsmenu.special.value = 123 # page ID having departments as subpages
temp.jsmenu.1 = TMENU
temp.jsmenu.1 {expAll = 0
wrap = <select name="email_to" class="form_dropdown"><option value="no department selected" class="form_dropdown">please select a department</option>|</select>
NO {before.data = field:subtitle
before.wrap = <option value="|" class="form_dropdown">
doNotLinkIt = 1
allWrap = | </option>
}
CUR < .NO
CUR = 1
CUR.before.wrap = <option value="|" SELECTED class="form_dropdown">
}
plugin.tx_thmailformplus_pi1.markers.pulldown_departments < temp.jsmenu
default settings: (since 3.5.0)
Many of you know the problem: you use the same mailformplus element several times within one project showing the form on several pages. After changing the form-HTML-template you have to edit each mailformplus element and assign the changed template once more in order to make the changes visible.
Or if you are using several mailformplus elements that are all sent to one emailaddress: if that emailaddress changes, you have to search and edit every mailformplus element on the page.
The default settings specified via TypoScript are the default values of the mailformplus element but are overridden by the settings you enter in the mailformplus element.
If you leave the field blank in the mailformplus element, the default value defined in TypoScript is used.
You can do tricky things with that like:
changing the required fields (checked serverside) depending on a radiobutton the user selected in the form.
Let's say, you give the user the possibility to check if he wants to be contacted via email or via telephone.
Of course you also have the two input fields in the form, but when the user checks “email”, the email field has to be filled out. If the user checks “telephone”, the telephone field is required.
this is how it's done:
[globalVar = GP:contact_me_via=email]
plugin.tx_thmailformplus_pi1.default.email_requiredfields = email,name
[end]
[globalVar = GP:contact_me_via=telephone]
plugin.tx_thmailformplus_pi1.default.email_requiredfields = tel,name
[end]
result if the user selected “email” and submitts the form:
result if the user selected “telephone” and submitts the form:
(available since 3.7, thx to Martin Kutschker)
This hook gives you the possibility to save or process the submitted fields after the form was successfully submitted.
Standard mailformplus functionality like sending mail(s) or inserting records are not influenced by this hook.
how to use the hook:
define a user-function which will do the processing
create a php file with a class and function which will be called when the form was submitted:
example:
class.tx_myext.php
content:
class tx_myext {function doit(&$params, &$ref){......
}
}
The variable $params will hold the following values:
$params[config] ... config variables passed via TypoScript: example: saveUserFunc.dummy = hello can be accessed by $params[config][dummy]
$params[data] ... all submitted GET and POST variables merged
activate the hook with TypoScript
You have to define the user function that should be called when the form was submitted correctly:
plugin.tx_thmailformplus_pi1.saveUserFunc = EXT:myext/class.tx_myext.php:tx_myext->doit
You can also define “variables” which will be passed to the user function:
plugin.tx_thmailformplus_pi1.saveUserFunc.dummy = hello
Q: Is it also possible to save two pictures?
A: Yes – see example in previous section
To-Do list
I never needed more functinality till now that's why these things are not implemented yet.
Testing if it works with more than one mailformplus element on a page
file-upload support currently only if you save data into the database.
maybe better “check fields” support (not only if the specified fiels are filled out or not – but e.g. Check for valid email or something like that)
multiple checkboxes having the same name are not processed correctly (because formular field is an array)