Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

Adding fields to sr feuser register registration form

From TYPO3Wiki
Jump to: navigation, search

This is small HowTo which explains how you can expand user registration form coming in extension sr_feuser_register with your custom fields.

For an example we will add "Place of Birth" to each (frontend) user. Follow these steps:

extend fe_users table

All information about users (more precisely frontend users) are stored in database table fe_users. Extend this table by field placeofbirth.

Note that it's not enough to just add a field by phpMyAdmin. You need to create an extension and put something like this into ext_tables.php

$tempColumns = array(
	"vat_id" => array(
		"exclude" => 1,
		"label" => "LLL:EXT:sl_timetracking/locallang_db.xml:fe_users.vat_id",
		"config" => array(
			"type" => "input",
			"size" => "20",
		)
	),
);


\TYPO3\CMS\Core\Utility\GeneralManagementUtility::addTCAcolumns("fe_users",$tempColumns);

Add the fields in the HTML template

You need to edit template file pi1/tx_srfeuserregister_pi1_css_tmpl.html in extension sr_feuser_register. Edit the file in the proper subparts. The subparts of interest are:

  • ###TEMPLATE_CREATE###
  • ###TEMPLATE_CREATE_PREVIEW###
  • ###TEMPLATE_INVITE###
  • ###TEMPLATE_INVITE_PREVIEW###
  • ###TEMPLATE_EDIT###
  • ###TEMPLATE_EDIT_PREVIEW###

and perhaps some of the email subparts.

Have a look at how the predefined fields are included in each of the subparts, and do the same for the fields you are adding.

The HTML for a field named myNewFieldName in the CREATE, INVITE and EDIT subparts would look like:

<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->
<dt>
	<label for="tx-srfeuserregister-pi1-myNewFieldName">###LABEL_MYNEWFIELDNAME###</label>
	<span class="tx-srfeuserregister-pi1-required">###REQUIRED_MYNEWFIELDNAME###</span>
</dt>
<dd>
	<!-- ###SUB_ERROR_FIELD_myNewFieldName### -->
	<p class="tx-srfeuserregister-pi1-error">###EVAL_ERROR_FIELD_myNewFieldName###</p>
	<!-- ###SUB_ERROR_FIELD_myNewFieldName### -->
	<!-- ###SUB_REQUIRED_FIELD_myNewFieldName### -->
	<p class="tx-srfeuserregister-pi1-error">###MISSING_MYNEWFIELDNAME###</p>
	<!-- ###SUB_REQUIRED_FIELD_myNewFieldName### -->
	<input id="tx-srfeuserregister-pi1-myNewFieldName" type="text" size="40" maxlength="50" title="###TOOLTIP_MYNEWFIELDNAME###" name="FE[fe_users][myNewFieldName]" class="tx-srfeuserregister-pi1-text" />
</dd>
<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->

In the case of a field of type textarea, check, radio and select, the HTML for the field should rather look like the following:

<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->
<dt>
	<label for="tx-srfeuserregister-pi1-myNewFieldName">###LABEL_MYNEWFIELDNAME###</label>
	<span class="tx-srfeuserregister-pi1-required">###REQUIRED_MYNEWFIELDNAME###</span>
</dt>
<dd>
	<!-- ###SUB_ERROR_FIELD_myNewFieldName### -->
	<p class="tx-srfeuserregister-pi1-error">###EVAL_ERROR_FIELD_myNewFieldName###</p>
	<!-- ###SUB_ERROR_FIELD_myNewFieldName### -->
	<!-- ###SUB_REQUIRED_FIELD_myNewFieldName### -->
	<p class="tx-srfeuserregister-pi1-error">###MISSING_MYNEWFIELDNAME###</p>
	<!-- ###SUB_REQUIRED_FIELD_myNewFieldName### -->
	###TCA_INPUT_myNewFieldName###
</dd>
<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->

In each PREVIEW subpart, you need to add lines like:

<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->
<dt>###LABEL_MYNEWFIELDNAME###</dt>
<dd>###FIELD_MYNEWFIELDNAME###</dd>
<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->

or

<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->
<dt>###LABEL_MYNEWFIELDNAME###</dt>
<dd>######TCA_INPUT_MYNEWFIELDNAME###</dd>
<!-- ###SUB_INCLUDED_FIELD_myNewFieldName### -->


Modify the TS template Constants and Setup

Using the Constant Editor, modify the value of the following constants of plugin tx_srfeuserregister_pi1: formFields: add to the list of fields the names of the fields you have defined and want to be displayed in the Frontend form. If the field is not in this list, the subpart

<!--###SUB_INCLUDED_FIELD_myNewFieldName###--> will be deleted;

requiredFields: add to the list of fields the names of the fields you have defined and want to be treated as required fields. If the field is not in the list OR if the field is in this list and is correctly filled, the subpart

<!--###SUB_REQUIRED_FIELD_myNewFieldName###--> will be deleted.

You may also specify in the TS template Setup some default values and validation rules to be applied by the extension to the additional fields. If there are no validation rules, you should set: plugin.tx_srfeuserregister_pi1.create.evalValues.myNewFieldName =

If your field is a select field and if you wish to enable multiple selection, you should also set: plugin.tx_srfeuserregister_pi1.parseValues.myNewFieldName = multiple Add the language labels for the new fields The language labels for the additional database fields should be added in Step1 above. These will be used by the Backend forms. The language labels used by the Frontend plugin should be added in the TS template setup using the method described in the Localization section of this document. For each language of interest to you with languageCode , you may need the following statements for each additional field with myNewFieldName: The basic field label:

plugin.tx_srfeuserregister_pi1._LOCAL_LANG.languageCode.myNewFieldName = myNewFieldLabel

The message displayed when the field is required but missing:

plugin.tx_srfeuserregister_pi1._LOCAL_LANG.languageCode.missing_myNewFieldName = missingRequiredFieldMessage

Same as previous but for the invitation form:

plugin.tx_srfeuserregister_pi1._LOCAL_LANG.languageCode.missing_invitation_ myNewFieldName = missingRequiredFieldMessageOnInvitationForm

The message displayed when a validation rule evalRuleName applicable to the field is not satisfied:

plugin.tx_srfeuserregister_pi1._LOCAL_LANG.languageCode.evalErrors_evalRuleName_myNewFieldName = errorMessageForEvalRule

Links

  • the tutorial is based on [1]