How to remove "Your website URL" field from comment forms in Silverstripe CMS

Tags: , , ,

It's obvious that “Your website URL” field in Silverstripe comment forms is a plum for spammers, so let's remove this field.

Comment forms' interface is defined in PageCommentInterface class (“cms\code\sitefeatures\PageCommentInterface.php”), we need to create our own interface for comment forms on top of this class. In order to do that create a file called “mysite\code\MyPageCommentInterface.php” and write the following to it:

class MyPageCommentInterface extends PageCommentInterface {
    public function PostCommentForm() {
        $form = parent::PostCommentForm();
        $fields = $form->Fields();
        return $form;

After adding a new file to your Silverstripe project you have to rebuild the file cache — execute “http://your-site/dev/build” script.

Then open “mysite/code/Page.php” file and rewrite PageComments method in your Page_Controller class:

public function PageComments() {
    $ret = parent::PageComments();

    // Substitute system page comments interface with ours
    if (get_class($ret) == 'PageCommentInterface') {
        $ret = new MyPageCommentInterface($this, 'PageComments', $this->data());

    return $ret;

Now “Your website URL” field in comment forms won't be shown, and all attempts to pass CommenterURL variable in a POST-request will be unsuccessful.

22 September 2011

Comments (frozen for the time being)

No one has commented on this page yet.

Интернет реклама