Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Add fields to PageComments form

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2063 Views
  • Richie
    Avatar
    Community Member
    18 Posts

    Add fields to PageComments form Link to this post

    I'm trying to add some fields to the $PageComments form. To do this I use the DataObjectDecorator to extend the PageCommentInterface. To start simple I overload the PostCommentForm and alter the field 'Your name' to 'Your - test - name'. Problem is that the 'default' form with 'Your name' is showing. Hopefully someone could give me a clue on what I'm doing wrong here? Thanks!

    ===mysite/code/CustomCommentInterface.php===

    class CustomCommentInterface extends DataObjectDecorator
    {

       function forTemplate()
       {
          return $this->renderWith('CustomCommentInterface');
       }
       
       function PostCommentForm() {
          Requirements::javascript('jsparty/behaviour.js');
          Requirements::javascript('jsparty/prototype.js');
          Requirements::javascript('jsparty/scriptaculous/effects.js');
          Requirements::javascript('cms/javascript/PageCommentInterface.js');
          
          
          $fields = new FieldSet(
             new HiddenField("ParentID", "ParentID", $this->page->ID),
             new TextField("Name", _t('CustomCommentInterface.YOURNAME', 'Your - test - name')));   
          
          if(MathSpamProtection::isEnabled()){
             $fields->push(new TextField("Math", sprintf(_t('CustomCommentInterface.SPAMQUESTION', "Spam protection question: %s"), MathSpamProtection::getMathQuestion())));
          }            
          
          $fields->push(new TextareaField("Comment", _t('CustomCommentInterface.YOURCOMMENT', "Comments")));
          
          $form = new PageCommentInterface_Form($this->controller, $this->methodName . ".PostCommentForm",$fields, new FieldSet(
             new FormAction("postcomment", _t('CustomCommentInterface.POST', 'Post'))
          ));
          
          $form->loadDataFrom(array(
             "Name" => Cookie::get("CustomCommentInterface_Name"),
          ));
          
          return $form;
       }
    }

    ===mysite/_config.php===

    Object::add_extension('PageCommentInterface', 'CustomCommentInterface');

  • Richie
    Avatar
    Community Member
    18 Posts

    Re: Add fields to PageComments form Link to this post

    Browsing the docs and forum some more but can't seem to find what I'm missing here. Someone? Anyway, thanks for your time!

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Add fields to PageComments form Link to this post

    Hey, I am not sure if this is what you are looking for but I added an email field to page comments although I did it by changing the core so there is prolly way to do it without hacking. The diff file i generated is here http://open.silverstripe.com/attachment/ticket/2576/diff.patch which should give you an idea of what worked.

    Good luck

    2063 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.