Question

Is it possible to add new custom editable fields to the module Peronal data? If so, how does this work? PHP my admin and add Mysql tables? Or can this be done via the contao backend? Please advise

No correct solution

OTHER TIPS

Its very much possible. I am not sure which contao version you are using now because they differ in how you create the database field.

Lets assume you want to add accept terms checkbox to the registration module.

Contao 2.11

In modules directory create a folder with the following structure

myModule/config/database.sql
myModule/dca/tl_member.php
myModule/languages/en/tl_member.php

In database.sql, create the field as follows

CREATE TABLE `tl_member` (

accept_terms char(1) NOT NULL default '', ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

In dca/tl_member.php, add the field to tl_member dca close to where login details are as follows.

$GLOBALS['TL_DCA']['tl_member']['palettes']['default'] = str_replace('login;','login,accept_terms;',$GLOBALS['TL_DCA']['tl_member']['palettes']['default']);

Create the field as follows(used to generate the checkbox input)

$GLOBALS['TL_DCA']['tl_member']['fields']['accept_terms'] = array(
        'label'     => &$GLOBALS['TL_LANG']['tl_member']['accept_terms'],
        'inputType' => 'checkbox',
        'eval'      => array( 'mandatory' => true, 'tl_class' => 'w50', 'feEditable' => true,'feViewable'=>true)
    );

Note: mandatory => true // make it a mandatory field feEditable => true // enable edit in module personal data or module registration feViewable=>true // make it appear in module personal data or module registration

in languages/en/tl_member.php, create the labels as follows

$GLOBALS['TL_LANG']['tl_member']['accept_terms']   = array('Terms & Conditions', 'I accept the terms and conditions of using this website.');

Contao 3

The structure is pretty much the same only that you don't need the database.sql i.e you can remove it and modify dca/tl_member.php as follows

$GLOBALS['TL_DCA']['tl_member']['fields']['accept_terms'] = array(
        'label'     => &$GLOBALS['TL_LANG']['tl_member']['accept_terms'],
        'inputType' => 'checkbox',
        'eval'      => array( 'mandatory' => true, 'tl_class' => 'w50', 'feEditable' => true,'feViewable'=>true),
            'sql'       => "char(1) NOT NULL default ''"
    );

Note the addition of this line 'sql' => "char(1) NOT NULL default ''" in the array.

Now go to the install tool and create your field in mysql. login to the backend, go to modules, your personal data module and you should be able to see your field there. Check it to include it to frontend fields and you are done.

Please not the consistency of using tl_member and accept_terms in all the directories

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top