Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

[SOLVED] Customising Member Profiles -> CheckboxSetField Problem


Reply


2 Posts   300 Views

Avatar
Optic Blaze

Community Member, 162 Posts

18 December 2013 at 9:16am

Hi there,

I am using the Member Profiles module from ajshort. I have extended the members class to allow for more fields. Everything is working well except i need a CheckboxSetField to allow for multiple selections. At the moment i get an 'Array to String conversion' error and it does not save correctly to the db.

Here is the code so far:
----------------------------------------------------------------------------
MyMemberExtension.php
-----------------------------------------------------------------------------
class MyMemberExtension extends DataExtension {
   
   private static $db = array(
   'CompanyName'=>'Varchar(255)',
   'CompanyTel'=>'Varchar(12)',
   'CompanyFax'=>'Varchar(12)',
   'CompanyAddress'=>'Varchar(255)',
   'CompanyEmail'=>'Varchar(255)',
   'CompanyWebsite'=>'Varchar(255)',
   'CompanyDescription'=>'Text',
   'CompanyCEO'=>'Varchar(100)',
   'IndustryGroup'=>'Enum(" ,Developer,EPC,Financier,Government,Installer,Independent Consultant,Legal,Manufacturer,NGO,Other")',
   'NumberEmployees'=>'Enum(" ,1-9,10-49,50-99,100-199,Over 200")',
   'Newsletter'=>'Enum("Yes,No")',
   'Sectors'=>'Varchar(255)'
   );

---------------------------------------------------------------------------------
MemberProfilePage.php
----------------------------------------------------------------------------------

public function AddForm() {
      return new Form (
         $this,
         'AddForm',
         $this->getProfileFields('Add'),
         new FieldList(      
         CheckboxSetField::create('Sectors', 'Which sectors are you intersted in?',array(
          'Wind'=>'Wind',
          'SWH'=>'SWH',
          'Biogas'=>'Biogas',
          'Biomass'=>'Biomass',
          'Waste Management'=>'Waste Management',
          'Hydro Electric'=>'Hydro Electric',
          'PV'=>'PV',
          'CSP'=>'CSP',
          'Other'=>'Other'
      )),
            new FormAction('doAdd', _t('MemberProfiles.ADD', 'Add'))
         ),
         new MemberProfileValidator($this->Fields())
      );
   }

Any help will be appreciated. Thanks

Avatar
Optic Blaze

Community Member, 162 Posts

22 December 2013 at 3:00am

Ok figured it out after ajshort pointed me in the right direction

You need to extend the updateMemberFormFields function like this:

public function updateMemberFormFields(&$fields) {
      
    $fields->push( new LiteralField('CompanyDetailsHeader', '<h2>Company details</h2>'));
$fields->push( new TextField('CompanyName', 'Company Name'));
$fields->push( new TextField('CompanyTel', 'Company Phone number'));
$fields->push( new TextField('CompanyFax', 'Company Fax number'));
$fields->push( new TextareaField('CompanyAddress', 'Company Address'));
$fields->push( new EmailField('CompanyEmail', 'Company Email Address'));
$fields->push( new TextField('CompanyWebsite', 'Company Website'));
$fields->push( new TextField('CompanyCEO', 'Company CEO'));
$myindustry = new DropdownField
('IndustryGroup', 'Select Industry Group',singleton('Member')->dbObject('IndustryGroup')->enumValues());
$myindustry->setEmptyString('-Please Select-');
$fields->push( $myindustry,'IndustryGroup');
$employee = new DropdownField
('NumberEmployees', 'Number of Employees in your company',singleton('Member')->dbObject('NumberEmployees')->enumValues());
$employee->setEmptyString('-Please Select-');
$fields->push( $employee,'NumberEmployees');
$fields->push( new CheckboxSetField('Sectors', 'Which sectors are you intersted in?',array(
"Wind"=>"Wind",
"SWH"=>"SWH",
"Biogas"=>"Biogas",
"Biomass"=>"Biomass",
"Waste Management"=>"Waste Management",
"Hydro Electric"=>"Hydro Electric",
"PV"=>"PV",
"CSP"=>"CSP",
"Other"=>"Other"
)));
}

Then it works