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
merrick_sd

Community Member, 99 Posts

22 November 2012 at 2:12am

Edited: 22/11/2012 3:17am

Access to undeclared static property: MollomField::$alwaysShowCaptcha

maybe its called $always_show_captcha

mollom> code > MollomField.php
line 15 static $always_show_captcha = false;

I was going to start a new topic as I'm trying to do a custom form using bootstrapform with mollom using SS 3.0.2.

mystie > config

 

    Debug::send_errors_to("debugs@mydomain......");

  MollomServer::setPublicKey('yes thats there');
  MollomServer::setPrivateKey('yes thats thre');
  SpamProtectorManager::set_spam_protector('MollomSpamProtector');

mysite > code > ContactPage.php


class ContactPage_Controller extends Page_Controller
{
	//Define our form function as allowed
	static $allowed_actions = array(
		'ContactForm'
	);
	
	//The function which generates our form
	function ContactForm() 
	{
      	// Create fields
	    $fields = new FieldList(
	
		DropdownField::create("Prefix","Title")
		      ->setSource(array('Mr.' => 'Mr.', 'Ms.' => 'Ms.', 'Mrs.' => 'Mrs.', 'Dr.' => 'Dr.', 'Rev.' => 'Rev.')), 
	   TextField::create("FirstName")->setTitle('Firstname'),
	   TextField::create("Surname")->setTitle('Surname')->setMaxLength(50),
	   
	   TextField::create("DaytimeTel")->setTitle('Daytime Contact Number'),
	   TextField::create("EveningTel")->setTitle('Evening / Weekend Contact Number'),
		new EmailField('Email', 'Email*'),
		new TextareaField('Comments','Enquiry*')
		);
	 	
	    // Create action
	    $actions = new FieldList(
	  	FormAction::create('SendContactForm', 'Send')
	      ->setStyle("primary")
	    );
		
		// Create validation
		$validator = new RequiredFields('Prefix','FirstName', 'Surname', 'Email', 'Comments');
		
		//return form fields,actions, validation
	   $form = BootstrapForm::create($this, 'ContactForm', $fields, $actions, $validator)->addWell()
	    ->setLayout("horizontal");
	    
	    // form fields and mollom fields mapping
	    $fieldMap = array('Prefix' => 'Prefix', 'FirstName' => 'FirstName', 'Surname' => 'Surname', 'Email' => 'Email', 'DaytimeTel' => 'DaytimeTel', 'EveningTel' => 'EveningTel','Comments' => 'Comments');
	    
	    // Update the form to add the protector field to it
	    $protector = SpamProtectorManager::update_form($form, null, $fieldMap);
	    return $form;
	
	}
 	
	//The function that handles our form submission
	function SendContactForm($data, $form) 
	{
	
	$DataContactSubmission = new ContactSubmission();
	$form->saveInto($DataContactSubmission);
	 	//Set data
		$From = $data['Email'];
		$To = $this->Mailto;
		$Subject = "HMY: Website Contact message";  	  
		$email = new Email($From, $To, $Subject);
		//set template
		$email->setTemplate('ContactEmail');
		//populate template
		$email->populateTemplate($data);
		//send mail
		$email->send();
	  	//return to submitted message
		Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");

	}

	//The function to test whether to display the Submit Text or not
	public function Success()
	{
		return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
	}
	
}	

Update
adding $always_show_captcha =true; to the mysite config got it to show.

I wasn't able to submit without getting the captcha correct.

note: there was no message when i got it wrong though! .. it just wouldn't let e get to the success page.

look on my other sites that use the userform module and ss2.whatever and the mollow files says
"Complete the words in the image"
and then on error
"You didn't type in the correct captcha text. Please type it in again."

I have also added Debug::show($response); on line 158 in mollomField.php


	$this->mollomFields['session_id'] = $session_id;
		$response = MollomServer::checkContent(
			$this->mollomFields['session_id'],
			$this->mollomFields['post_title'],
			$this->mollomFields['post_body'],
			$this->mollomFields['author_name'],
			$this->mollomFields['author_url'],
			$this->mollomFields['author_mail'],
			$this->mollomFields['author_openid'],
			$this->mollomFields['author_id']
		);
		Debug::show($response);

partly solved
doh!
From what i can tell its rather important you map field names to at least ONE to be checked.

ie: actually try and match them up with

$this->mollomFields['post_title'],
$this->mollomFields['post_body'],
$this->mollomFields['author_name'],
$this->mollomFields['author_url'],
$this->mollomFields['author_mail'],
$this->mollomFields['author_openid'],
$this->mollomFields['author_id']

$fieldMap = array('Prefix' => 'Prefix', 'FirstName' => 'author_name', 'Surname' => 'author_name', 'Email' => 'author_mail', 'DaytimeTel' => 'DaytimeTel', 'EveningTel' => 'EveningTel','Comments' => 'post_body');
[\code]


this has got the capatch to display and it works.

but there is still nothing in the way of helpful text to guid the end user.


Go to Top