Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » [SOLVED] Customising Member Profiles -> CheckboxSetField Problem

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 254 Views
  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    [SOLVED] Customising Member Profiles -> CheckboxSetField Problem Link to this post

    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

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: [SOLVED] Customising Member Profiles -> CheckboxSetField Problem Link to this post

    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

    254 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.