This project is no longer maintained and no further public releases are planned.

No further support will be given.

Feel free to fork the git repository.

Finisher\DB

Saves submitted values into a specified DB table.

The data saved to DB is accessible through template markers, e.g.: ###value_saveDB|tablename|field### or ###value_saveDB|fe_users|username###. If data is saved to the same table more than once (i.e. multiple rows are created or updated), a number suffix is added to the table name, e.g.: ###value_saveDB|fe_users_2|username###.

Version added

1.0.0

TypoScript path

plugin.Tx_Formhandler.settings.finishers.x copy to clipboard

Properties

.table

The table name to store the data into

Data type

String | cObj

Version added

1.0.0

.key

The field with the primary key

Data type

String | cObj

Default value

uid

Version added

1.0.0

Example code

key = uid

.key_value

Use this to specify your own value for the key field in an UPDATE query.

The query will look like this:

UPDATE table SET field=value WHERE key=key_value

Data type

String | cObj

Version added

1.0.0

.andWhere

Enter an additional where clause used for the SQL query to update a record. The “AND” in front will be added by Formhandler, please do not add it yourself.

Data type

String | cObj

Version added

1.0.0

.updateInsteadOfInsert

Does not store the values as a new row in the table, but tries to update an existing record.
Needs a uid set in GET/POST parameters.
Add a hidden field named the value entered in “key” to your form. Don't forget to add the formValuePrefix!

Data type

Integer (0,1,2)

Version added

1.0.0

.insertIfNoUpdatePossible

If the update fails because the record to be updated does not exist, a new record will be created in the table. This only works if updateInsteadOfInsert is set to 1.

Data type

Integer (0,1,2)

Version added

1.0.0

.disableUpdateUidFallback

Disable the default fallback used when searching for the UID to update.

Normal fallback:

  1. Use "key_value"
  2. Search in GET/POST values using "key"
  3. Use the last inserted UID stored by Finisher\DB (in case multiple records are inserted)

Data type

Boolean | cObj

Version added

1.3.0

.condition

Enter a condition in PHP syntax to be evaluated before the database operations. Only if the condition evaluates true, the database operations will be executed.
You can enter form field names which will be replaced with the entered values.

Data type

String | cObj

Version added

1.0.0

Important

THIS FEATURE WAS REMOVED IN VERSION 1.6.1

Example code

condition = agree === '1'

“agree” will be replaced with the value of the form field.

.fields

Mapping of table fields to submitted values.

Data type

Array

Version added

1.0.0

Example code

fields {
  [db_field].mapping = [form_field]
}
fields {
  header.mapping = name
}
fields {
  header.mapping = arrayField|arrayValue
}

.fields.[db_field].ifIsEmpty

Define a default value if the user did not enter anything in the form field.

Data type

String | cObj

Version added

1.0.0

.fields.[db_field].nullIfEmpty

If the user did not enter anything in the form field, a NULL value is inserted into database

Data type

Integer (0,1,2)

Version added

1.0.0

.fields.[db_field].zeroIfEmpty

If the user did not enter anything in the form field, a zero value (int: 0) is inserted into database

Data type

Integer (0,1,2)

Version added

1.0.0

.fields.[db_field].separator

If the field value is an array (e.g. check boxes) you can enter a separator to save the value imploded into DB.

Data type

String | cObj

Default value

,

Version added

1.0.0

.fields.[db_field].special

There are some special values available:

sub_datetime
sub_tstamp
ip
inserted_uid
files
saltedpassword (explainedbelow)

Should not require further explanation.

inserted_uid

When using this value you can set the according table using special.table
The field value will be set with a uid value of a record inserted by another Finisher\DB before the current one. Use this to store data into more than one table. Example in section How to store data into more than one DB table.

date

Added in version 1.4.0. Allows to convert a date entered in the form (e.g. using a datepicker) to a timestamp before storing the value to the database.

The possible TS options for the field mapping are "field" and "dateFormat". Set the name of the form field holding the date string in "field" and use "dateFormat" to specify the date format used.

If you are using PHP < 5.3.0 you can only use "d", "m" and "y" to specify the date format.
With PHP 5.3.0 Formhandler uses DateTime::createFromFormat to convert the date to a timestamp.

datetime

Added in version 1.4.0. Allows to convert a date and time entered in the form (e.g. using a datepicker) to a timestamp before storing the value to the database.

The possible TS options for the field mapping are "field" and "dateFormat". Set the name of the form field holding the datetime string in "field" and use "dateFormat" to specify the datetime format used.

You can use this option only if you are using PHP 5.3.0 or higher! Formhandler uses DateTime::createFromFormat to convert the datetime to a timestamp.

saltedpassword

Added in version 1.7.0. Allows you to salt an entered password entered in the configured field. Formhandler calls EXT:saltedpasswords to encrypt the password.

files

Added in version 1.7.0. Allows to write file information into database.

"field" is the field name of the upload field.
"separator" is an optional separator for file arrays (DEFAULT: ,)
"index" is an optional index to access in the files array. Use this if you want to access information of a specific file (e.g. the second one uploaded).
"info" is a scheme which info should be stored.

Available info:

uploaded_path - Absolute upload path
uploaded_name - Name of the file
uploaded_folder - Relative upload path
uploaded_url - URL to the uploaded file
name - Original file name
size - File size in byte
type - The MIME type

Data type

String | cObj

Version added

1.0.0

Example code

10.class = Finisher\DB
10.config {
    table = tt_content
    key = uid

    fields {
        header.special = date
        header.special {
            format = d.m.Y
            field = name
        }
        bodytext.special = datetime
        bodytext.special {
            format = d.m.Y H:i
            field = email
        }
        password.special = saltedpassword
        password.special {
            field = password
        }
        image {
           special = files
           special {
              field = file
              separator = |
              info = [uploaded_path][uploaded_name]
           }
        }
        filetype {
           special = files
           special {
              field = file
              separator = |
              info = [type]
           }
        }
        pid.mapping = TEXT
        pid.mapping {
            value = {TSFE:id}
            insertData = 1
        }
        CType = text
    }
}

.fields.[db_field].preProcessing

Preprocesses the value before saving to the database.

Data type

cObj

Version added

1.0.0

Example code

fields {
  header {
    preProcessing = USER
    preProcessing.userFunc = user_helper->appendSomething
    mapping = firstname
  }
}

.fields.[db_field].postProcessing

Postprocesses the value before saving to the database. Enables you to override the processing of Formhandler, if you are not satisfied with it.

Data type

cObj

Version added

1.0.0

Example code

fields {
  header {
    postProcessing = USER
    postProcessing.userFunc = user_helper->appendSomething
    mapping = firstname
  }
}