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.

We've moved the forum!

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.

All other Modules /

Discuss all other Modules here.

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

Adding Mollum to a Custom Forim


Go to End


9 Posts   5672 Views

Avatar
anebg

Community Member, 8 Posts

3 November 2009 at 10:51am

My form page-type was derived from this tutorial. http://www.ssbits.com/creating-a-simple-contact-form/
In fact, the code was the same.

This is my form code.

class ContactPage_Controller extends Page_Controller
{
function ContactForm() {
// Create fields
$Params = Director::urlParams();

$fields = new FieldSet(
new TextField('Name', 'Name*'),
new EmailField('Email', 'Email*'),
new TextareaField('Comments','Comments*')
);

// Create action
$actions = new FieldSet(
new FormAction('SendContactForm', 'Send')
);
// Create action
$validator = new RequiredFields('Name', 'Email', 'Comments');

return new Form($this, 'ContactForm', $fields, $actions, $validator);
}

I tried changing
return new Form($this, 'ContactForm', $fields, $actions, $validator);

to

$form = new Form($this, 'ContactForm', $fields, $actions, $validator);
$protector = SpamProtecterManager::update_form($form, 'Captcha');
if($protector) $protector->setFieldMapping('Name', 'Email','Comments');
return $form;
And it ran fine, but I never see the captcha field.
How can I test out that it is working? I tried out some -spammy- comments such as free viagra and they went through... So Im kinda worried. Should there be something to check before it sends the email?
Or are those 3 lines it?

Thanks

Avatar
Willr

Forum Moderator, 5523 Posts

3 November 2009 at 1:23pm

You can check to see if the form should display by setting MollomField::$alwaysShowCaptcha = true; in your _config file. This will tell you if your mollom field is added correctly and whether your key works.

Avatar
anebg

Community Member, 8 Posts

3 November 2009 at 1:26pm

I tried it and I got this...

Fatal error: Access to undeclared static property: MollomField::$alwaysShowCaptcha in /home2/fullplat/public_html/mollom/_config.php on line 5

Did I forget installing a module or something?

Avatar
Willr

Forum Moderator, 5523 Posts

3 November 2009 at 1:34pm

Sorry perhaps this is a new feature in trunk. Try downloading the mollom daily build and see if you still get that error - http://silverstripe.org/assets/modules/trunk/mollom-trunk-r87203.tar.gz

Avatar
anebg

Community Member, 8 Posts

3 November 2009 at 1:55pm

I think i have to upgrade silverstripe to the .2 version and then upgrade my spam and mollum modules... It's going 2 take some time, but thanks for the info and I will reply if I find anymore trouble (plz subscribe)

Thank you

Avatar
Dave L

Community Member, 60 Posts

15 March 2010 at 11:09pm

Edited: 15/03/2010 11:13pm

Hijacking this thread...

Basically trying the same thing, using Mollom with a custom form and form template. I set up a form as usual then:

      $actions = new FieldSet(
         new FormAction('doContactUs', "submit")
      );

      $form = new ContactUsForm($this, 'contactUsForm', $fields, $actions);
      SpamProtectorManager::update_form($form, null, array('Name', 'Email', 'Company', 'Message'));

I've gotten as far as the above along with getting Mollom field showing in my form template (truncated):

 <form $FormAttributes>
   <fieldset>
        $dataFieldByName(Name)
        $dataFieldByName(Message)
        $dataFieldByName(MollomField)
        $dataFieldByName(SecurityID)
        <% if Actions %>
           <% control Actions %>$Field<% end_control %>
        <% end_if %>
   </fieldset> 
</form>

However, like anebg my form submits without any indication Mollow is doing anything. It's like there is some hook during form submission missing due to a custom template/form?

I tried your method and download but first I get the same error as anebg when adding the setting to _config.php, then when I update to the download you link I get the error "Class MollomSpamProtector contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (SpamProtector::getFieldName, SpamProtector::updateForm, SpamProtector::setFieldMapping) in /Users/dlowndes/Sites/bluepacific/webroot/mollom/code/MollomSpamProtector.php on line 45"

In any case, it'd be nice to know if the Mollom module actually works with custom forms and templates so this can be documented (or stated as such). There is not much information on this use case.

I am using the download versions of Mollown and SpamProtector at silverstripe.org/modules.

Cheers

Dave

Avatar
Nathan Cox

Community Member, 99 Posts

16 March 2010 at 5:48pm

Should probably note that it doesn't work if you're logged in to the CMS at the time (safe to assume you're not spamming your own site).

Also make sure you have it set up in _config.php:

Mollom::setPublicKey('code_from_mollom');
Mollom::setPrivateKey('other_code_from_mollom');
SpamProtectorManager::set_spam_protector('MollomSpamProtector');

Failing that, try have a look in MollomField::validate() to see what it's doing on form submission. Eg find this line:

$response = MollomServer::checkContent($mollom_session_id, $postTitle, $postBody, $authorName, $authorUrl, $authorEmail, $authorOpenId);

and add Debug::show($response) to see what Mollom is saying, assuming it gets that far.

Avatar
_Jam_

Community Member, 9 Posts

31 January 2011 at 6:31am

Hi!

I hope somebody could confirm if mollom works with custom forms and solve this issue. Thanks!

Go to Top