Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

1.5. Various examples:

multipage form example

Have a look in the  /tx_thmailformplus/example_form/ directory. You will find the following files there:

  1. mailformplus_demo.html ... single form example with file upload

  2. multipage.html ... multipage form example with fileupload and error checks

  3. multipage_TypoScript_setup.txt ... TS for multipage.html example

saveLog configuration 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)

markers example

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:

  1. a page having the departments as subpages

  2. use the “subtitle” field of the department pages to store the email-addresses for each department.

  3. 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 example

 (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:

Hook for post-processing submitted fields example

(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:

  1. 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:

file:

class.tx_myext.php

file 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

  1. 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

print template example

If you want to show the user a summary of the submitted form (after it was successfully submitted) to give him/her the possibility to print out what he/she filled out, you have to define this ###TEMPLATE_PRINT### subpart.

Note:

  1. the PRINT-subtemplate has to be HTML.

  2. this functionality only makes sense if you do a redirect to a “thank you” page – otherwise you can fill the ###TEMPLATE_SUBMITTED_OK### subtemplate showing a summary of the submitted form.

After the form got submitted, the replaced PRINT-subtemplate is stored in the user-session.

To show the summary on the page, you have to fetch the session value with a user-function and print it out on the page.

example PRINT-subtemplate:

<!-- ###TEMPLATE_PRINT### begin -->
You just filled out the following fields:<br>
Name: ###name###<br>
Subject: ###subject###<br>
<br>
you uploaded the following files:
###photo###
<br>
###cv###
<br>
<!-- ###TEMPLATE_PRINT### end -->

example User-func for fetching the session value:

see th_mailformplus/example_form/mailformplus_userfunc.inc.php

example TypoScript for fetching the value

includeLibs.mailformplus_functions = fileadmin/mailformplus_userfunc.inc.php
################################
# outputs the PRINT template below normal page content
# main content
################################
temp.main_content = COA
temp.main_content {
  10 < styles.content.get
  20 = USER
  20.userFunc = user_mailformplus_userfunc->user_mailformplusPrint
}
...
page.10.subparts.CONTENT_MAIN < temp.main_content