contaobayern / contao-member-contact-settings
Member contact settings extension for Contao Open Source CMS
Installs: 144
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Type:contao-module
Requires
- php: >=5.6
- contao-community-alliance/composer-plugin: ~2.4 || ~3.0
- contao/core-bundle: ~3.5 || ~4.4
README
Member contact settings extension for Contao Open Source CMS
Overview
This module enhances the core modules Registration
and MemberData
by adding fields that
control the allowed contact settings for the registered frontend user.
Installation via Composer
Search package contaobayern/contao-member-contact-settings
and install as usual.
For Contao 4.4.x use the Contao Manager to install the extension.
Manual Installation
- Download the files from the GitHub repository. Rename the folder to
member-contact-settings
and save undersystem/modules
. - Update your database and clear the internal cache.
Please note
This module's JavaScript will not work with table layouts (i.e. if "Tableless layout" is not checked in the module's definition). This applies to Contao 3 only, as Contao 4 only has templates for tableless layouts. So if you want to use this extension with table layouts you must uncheck the "Control field dependencies with JavaScript" option in your registration and personal data frontend modules.
Setup
The setup is the same for both frontend modules (registration and member data):
- Create a new frontend module of the type "registration" or "member data".
- Define the form as usual.
- With the new fields you can add dependencies. For example if you add "contactPhone" the field "phone" will become mandatory when the user checks "contactPhone". A list of all dependencies is given below.
- Sort the field as you wish. It makes sense to put the dependent fields right below the field from which they depend.
- By default field dependencies are controlled on client side via JavaScript (jQuery must be enabled in page layout). If you do not want to use JavaScript setting of mandatory status you can uncheck the according option.
- With the "Toggle visibility of dependent fields" option you can choose if depedent fields shall be hidden when they are not mandatory (can only be used with JavaScript enabled).
New fields and dependencies in tl_member
Adding your own dependencies
Dependencies are defined in the tl_member
DCA. In the eval
array of each field which has dependencies
there is a new entry dependents
:
$GLOBALS['TL_DCA']['tl_member']['fields']['contactLetter'] = [ // ... 'eval' => [ // ... 'dependents' => [ 'mandatory' => ['street', 'postal', 'city', 'country'], 'visibility' => ['street', 'postal', 'city', 'country'], ], // ... ] ]
The array mandatory
contains the names of the fields which shall be set to mandatory when the parent
field is checked. The array visibility
contains the names of the fields which shall be shown or hidden
according to the parent field.
You can add or modify dependencies in the system\config\dcaconfig.php
file.
For example if you want to add state
to the dependencies of contactLetter
. You can do so by adding
the following code to system\config\dcaconfig.php
:
$GLOBALS['TL_DCA']['tl_member']['fields']['contactLetter']['eval']['dependents']['mandatory'][] = 'state'; $GLOBALS['TL_DCA']['tl_member']['fields']['contactLetter']['eval']['dependents']['visibility'][] = 'state';
You can also create new dependencies for your own fields wherever you need them:
$GLOBALS['TL_DCA']['tl_member']['fields']['myCheckbox']['eval']['dependents'] = [ 'mandatory' => ['fieldA', 'fieldB', 'fieldC'], 'visibility' => ['fieldA', 'fieldB', 'fieldC'], ];
Attention: a field which is mandatory by default should not be put in any dependents list. Otherwise its mandatory status will be controlled by the parent field which is unwanted because the field should always be mandatory.