Jump to:

23364 Posts in 18125 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Page Comments Required Fields / Validator?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 2068 Views
  • Pix
    Avatar
    Community Member
    130 Posts

    Page Comments Required Fields / Validator? Link to this post

    How would I ad required filed to my page comments? It seems like I can submit a comment with no data in any of the fields, and I would like to be able to require a comment and name in the very least.

    Thank you!

  • Pix
    Avatar
    Community Member
    130 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    Anyone know about this or has done this before? I'd really like to be able to require a comment and a name for submission. I've also added an email field to the comment form, so maybe require that too....but at least a comment and a name!

    Thank you

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    The only validation is via javascript, this is fixed in the next alpha preview of comments (still in testing) but if you want to add validation:

    mysite/_config

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

    mysite/code/RequiredComments.php

    <?php
    class RequiredComments extends Extension {

    function updatePageCommentForm($form) {
    $form->setValidator(new RequiredFields(array('Name', 'Comment')));
    }
    }

    Commenting has basically been rewritten recently by myself (will be up on github within the week) which makes it much easier to extend but since its a major change it'll only be available for the next major release of SS.

  • Pix
    Avatar
    Community Member
    130 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    Excellent! Thank you for the help, that looks easy.

    Wow, a new version of comments? Will that change how things are extended? I'm fairly new to SilverStripe but LOVING it, this is such an awesome CMS. Anyway I just went through this tutorial to add an e-mail field to the comments, but if there will be a new version of comments that will change how things are extended maybe I should wait for that? Sorry if this sounds like a really dumb question, but when you say it will be on github within the week, does that mean we could grab it from there and integrate it into our current version of the CMS, or must we wait for the next version?

  • Pix
    Avatar
    Community Member
    130 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    Hi Will,

    Sorry to bother you with this, but I can't seem to get the validation to work. I've looked at everything, checked it word for word to the code, and I can still submit completely blank comments. I even disabled my captcha in case there was some sort of funny conflict that I would have no idea about. I am ready to jump off a bridge, do you think I am missing anything? I am using v2.4.3, thanks....

  • Pix
    Avatar
    Community Member
    130 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    Hi!

    Can anyone comment on what I might be doing wrong in getting validation to work on page comments? I can't seem to get this code to work. Is anyone validating their page comment fields with this method or a different method?

    Thanks!

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    Hm maybe it doesn't like being on an extension. Perhaps try alter the actual Form code in PageCommentInterface.php to add validation to the new Form(.. part (tutorial 3 covers what you need to do to add validation).

  • Pix
    Avatar
    Community Member
    130 Posts

    Re: Page Comments Required Fields / Validator? Link to this post

    OK THANKS I'll give it a go. Thanks for all you do for this community Will, SilverStripe is awesome but couldn't be much of anything to the public without the kind support of people like you :0)

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