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

1.10. Features

Validation of field values

JavaScript validation

Example

If you have activated validation JS in constants (default), than you can validate values of textfields just after input in frontend:

Example: Mandatory check

Example: E-Mail check

Check for:

This validation of textfields are currently possible:

  1. Mandatory

  2. E-Mail

  3. URL

  4. Numbers

  5. Numbers (with comma or point)

  6. Letters

  7. Letters and numbers

Error Message:

Note: Current error messages are in german and english – you can change or add your own messages via locallang or typoscript (see above)

Stylesheet classes to manipulate validation messages and input fields:

  1. If error in inputfields: <input class=“validation-failed” />

  2. If no error in inputfields: <input class=“validation-passed” />

  3. DIV Layer of errormessage: <div class=”powermail_mandatory_js”>error</div>

PHP validation

Email of sender

Email of user will be automaticly checked, as soon as the email field is selected in backend

Setting a field to mandatory via typoscript instead of flexform setting

plugin.tx_powermail_pi1 {
validate.uid41.required = 1
}

With this possibilitiy you can set fields to required, if another field was not filled (phone field could be mandatory if email field is empty)

[globalVar = GP:tx_powermail_pi1|uid40= ]
[else]
plugin.tx_powermail_pi1.validate.uid66.required = 1
[end]

Autocheck via typoscript

Use typoscript to check any field like (example to check uid41 if it is an email):

plugin.tx_powermail_pi1 {
validate.uid41.auto = email
validate.uid41.errormsg = Please check your email, there is an error!
}

This autochecks are possible:

  1. email: check if value is an email

  2. url: check if value is a correct url

  3. numbers: only numbers allowed

  4. phone: numbers and / and + and - allowed

  5. alphanum: only numbers and characters allowed

Manual check via typoscript (using regulare expressions)

Use typoscript (in the setup) to check any field like (example to check uid41 if it is an url):

plugin.tx_powermail_pi1 {
validate.uid41.expression = ^(http://)?([a-z0-9-]+\.)+([a-z0-9-]{2,3})$^
validate.uid41.errormsg = Sorry, but this is not a correct URL, try again!
}

You can enter any regulare expression go check your field values

Further regex examples:

plugin.tx_powermail_pi1 {
validate.uid23.expression = /^alex\@wunschtacho\.de$/
validate.uid23.errormsg = Sorry, but this field should contain alex@wunschtacho.de!

}

plugin.tx_powermail_pi1 {
validate.uid25.expression = /^###UID26###$/
validate.uid25.errormsg = Sorry, but your password fields are different – try again!

}

Saving db values to any db table

Introduction

With powermail you can save your values to any db table (e.g. fe_users or tt_address)

Example typoscript part in setup

plugin.tx_powermail_pi1 {

# extern db entry (example for tt_adress)

dbEntry {

# enable or disable db entry for tt_address

tt_address._enable = TEXT

tt_address._enable.value = 1

# add mm relation to uid 2 of tt_address_group (via mm table)

tt_address._mm = COA

tt_address._mm.10 = COA

# 1 is always the mm table

tt_address._mm.10.1 = TEXT

tt_address._mm.10.1.value = tt_address_group_mm

# 2 is always the other table

tt_address._mm.10.2 = TEXT

tt_address._mm.10.2.value = tt_address_group

# 3 is always the uid of the other table to get a relation to this (in this case uid2 of tt_address_group)

tt_address._mm.10.3 = TEXT

tt_address._mm.10.3.value = 2

# table "tt_address" with field "email" is a static value => alexander.kellner@einpraegsam.net

tt_address.email = TEXT

tt_address.email.value = alexander.kellner@einpraegsam.net

# table "tt_address" with field "pid" is the current pid (e.g. 12)

tt_address.pid = TEXT

tt_address.pid.field = uid

# table "tt_address" with field "tstamp" is the current time as timestamp (like 123456789)

tt_address.tstamp = TEXT

tt_address.tstamp.data = date:U

# table "tt_address" with field "address" is the current formatted time (like "Date: 20.01.2009")

tt_address.address = TEXT

tt_address.address.data = date:U

tt_address.address.strftime = Date: %d.%m.%Y

# table "tt_address" with field "name" is the value from powermail (tt_content uid 88) field uid18 (###uid18###)

tt_address.name = TEXT

tt_address.name.data = TSFE:fe_user|sesData|powermail_88|uid18

# table "tt_address" with field "last_name" is the value from powermail (tt_content uid 88) field uid18 (###uid18###)

tt_address.last_name = TEXT

tt_address.last_name.data = TSFE:fe_user|sesData|powermail_88|uid18

# table "tt_address" with field "company" is the value from powermail (tt_content uid 88) field uid21_1 (###uid21_1###) (e.g. a checkbox value)

tt_address.company = TEXT

tt_address.company.data = TSFE:fe_user|sesData|powermail_88|uid21|1

}

}

Some information about saving to other tables

  1. Saving is available only if table and field are existing

  2. Every table contains one record

  3. If you want to use more than only one  mm relation, you can use  tt_address._mm.10 and  tt_address._mm.20 and so on...

  4. With this small add to powermail, you can use powermail for many features like guestbook form, tipafriend form, fe_user registration, tt_address registration and so on...

Prefilling fields

Sequence of prefilling fields

  1. Is there a fitting piVar like &tx_powermail_pi1[uid11]=text, than use this value, and if not...

  2. Is there a value in the session, so fill field with this value, and if not...

  3. Is there a value set in the backend flexform, take this value, and if not...

  4. Should this field filled with logged in fe_user datas (set in backend), take this value, and if not...

  5. Was typoscript used to prefill a field, use this (see example below), and if not

  6. Don't fill

Example to prefill fields via typoscript setup

plugin.tx_powermail_pi1 {

prefill {

# fill field uid997 with a static text

uid997 = TEXT

uid997.value = example value

# fill field uid998 with current timestamp

uid998 = TEXT

uid998.data = date:U

# fill field uid998 with current date like "Date: 20.01.2009"

uid996 = TEXT

uid996.data = date:U

uid996.strftime = Date: %d.%m.%Y

# fill field uid995 with IP address of the user

uid995 = TEXT

uid995.data = getIndpEnv:REMOTE_ADDR

}

}

Maybe it's usefull to fill some hidden fields with hidden but important values (IP address, timestamp, Language, GET params, etc..)

Fighting spam

  1. We suggest you to use the extension wt_spamshield for fighting spam entries (see details in manual wt_spamshield)

  2. You can also use captcha (see next paragraph)

Integrate captcha to your form

Description

  1. First of all install a captcha extension like captcha or sr_freecap

  2. Be sure, that you have chosen this extension via constants (captcha or sr_freecap)

  3. As you can add a normal textfield, you can add a captcha field, thats all

  4. If you have installed captcha AND sr_freecap, the extension use sr_freecap

  5. If you have not installed one of this extensions, an error message in frontend is shown

Examples

Example: Using captcha

Example: Using sr_freecap

Example: Using jm_recaptcha

NOTE: jm_recaptcha works only if you don't use multiple PHP – or if you want to use multiple PHP, than integrate this captcha on the last page

Add new field: Selectorbox with values from database

Step by step

  1. Add new field (typoscript) and use (e.g.) lib.object in this field

  2. Add your typoscript in the setup field to fill lib.object (see example below)

Example typoscript for selectorbox from table tt_address

# Get all tt_address datas from pid=5

lib.object = COA_INT

lib.object {

10 = TEXT

10.value = <label for="uid33">Select:</label>

20 = CONTENT

20.wrap = <select id="uid33" name="tx_powermail_pi1[uid33]" size="1">|</select>

20 {

table = tt_address

select {

pidInList = 5

orderBy = name

}

renderObj = COA

renderObj {

10 = COA

10 {

10 = TEXT

10 {

field = uid

wrap = <option value="|">

}

20 = TEXT

20 {

field = name

wrap = |</option>

}

}

}

}

}

Example output (html) of example typoscript

<label for="uid33">Select:</label>

<select id="uid33" name="tx_powermail_pi1[uid33]" size="1">

<option value="23">Name1</option>

<option value="24">Name2</option>

</select>