Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Adding Mollum to a Custom Forim

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 3192 Views
  • anebg
    Avatar
    Community Member
    8 Posts

    Adding Mollum to a Custom Forim Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    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.

  • anebg
    Avatar
    Community Member
    8 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    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

  • anebg
    Avatar
    Community Member
    8 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    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

  • Dave L
    Avatar
    Community Member
    56 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    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

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    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.

  • _Jam_
    Avatar
    Community Member
    9 Posts

    Re: Adding Mollum to a Custom Forim Link to this post

    Hi!

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

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