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!
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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!
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
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.
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?
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....
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!
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).
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)