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.

General Questions

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 Comments Required Fields / Validator?


Go to End
Reply

10 Posts   2168 Views

Avatar
Pix

5 December 2010 at 8:38pm Community Member, 145 Posts

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!

Avatar
Pix

6 December 2010 at 9:23am Community Member, 145 Posts

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

Avatar
Willr

6 December 2010 at 8:07pm Forum Moderator, 5511 Posts

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.

Avatar
Pix

6 December 2010 at 8:30pm (Last edited: 6 December 2010 8:31pm), Community Member, 145 Posts

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?

Avatar
Pix

15 December 2010 at 12:20pm Community Member, 145 Posts

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

Avatar
Pix

17 December 2010 at 10:15am (Last edited: 17 December 2010 10:15am), Community Member, 145 Posts

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!

Avatar
Willr

17 December 2010 at 10:28am Forum Moderator, 5511 Posts

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

Avatar
Pix

17 December 2010 at 11:44am Community Member, 145 Posts

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)

Go to Top