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.

Archive /

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

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

Add fields to PageComments form


Reply


3 Posts   2241 Views

Avatar
Richie

Community Member, 18 Posts

10 December 2008 at 11:28pm

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');

Avatar
Richie

Community Member, 18 Posts

14 December 2008 at 9:00am

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

Avatar
Howard

Community Member, 215 Posts

14 December 2008 at 7:54pm

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