Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » UserDefinedForms - Add more fields choice

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 1096 Views
  • Kisskool
    Avatar
    Community Member
    11 Posts

    Re: UserDefinedForms - Add more fields choice Link to this post

    Hi ! This is my custom code to add some fields to the form :

    mysite/code/MyMember.php

    <?php

    class MyMember extends DataObjectDecorator {

       //Add extra database fields
       function extraStatics(){
          return array(
             'db' => array(
              'Pseudo' => 'Varchar(255)',
              'TheWebsite' => 'Varchar(255)',
              'ConfirmationEmail' => 'Varchar(255)'
             )
          );
       }
       
       public function updateMemberFormFields(&$fields) {
          $fields->push(new TextField('Pseudo', 'Pseudo'));
          $fields->push(new TextField('TheWebsite', 'TheWebsite'));
          $fields->push(new EmailField('ConfirmationEmail', 'ConfirmationEmail'));
       }

    }

    ?>

    mysite/_config.php

    Object::add_extension('Member', 'MyMember');

    If you find errors or faults, please let me know !

    Regarding the confirmation email field, I think the best way to check if fields are matched is :

    -First, get the form. Do you think I need to create a new php file, e.g. MyForm.php with an extended MemberProfilePage class ? Or can I get the form into an another class in my MyMember.php ?
    I have not yet found how can I get the form...I already tried this code, but I don't know where I need to put it :

    function getCMSFields() {
       $fields = parent::getCMSFields();
    //get the email field
       $email = $fields->FieldByName('Email');
    //then, get the value of the email field, but how ?
    //return fields
       return $fields;
    }


    Do you think it's a good way ? Does this code can work ?

    -Second, extract the email fields values. With loadDataFrom(), or getData(), or something else ?

    -Thirdly, check if the email fields are matched before form submitting. I really don't know how can I do this.

    -Finally, submit the form.

    Is this the best way ? Or do you know something else easier ?

  • Kisskool
    Avatar
    Community Member
    11 Posts

    Re: UserDefinedForms - Add more fields choice Link to this post

    Hi !

    For the time being, I have no time to work on this confirmation email field (I must work on a problem with the blog RSS Feed).
    But if (or when) I have time, I'ill continue to find the solution.

    1096 Views
Page: 1 2
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.