get('FormSpamProtectionExtension', 'default_spam_protector'); } if ($protector && class_exists($protector)) { return Injector::inst()->create($protector); } else { return null; } } /** * Activates the spam protection module. * * @param array $options * @return Object */ public function enableSpamProtection($options = array()) { // captcha form field name (must be unique) if (isset($options['name'])) { $name = $options['name']; } else { $name = Config::inst()->get('FormSpamProtectionExtension', 'field_name'); } // captcha field title if (isset($options['title'])) { $title = $options['title']; } else { $title = ''; } // set custom mapping on this form $protector = self::get_protector($options); if (isset($options['mapping'])) { $protector->setFieldMapping($options['mapping']); } if ($protector) { // add the form field if ($field = $protector->getFormField($name, $title)) { $field->setForm($this->owner); // Add before field specified by insertBefore $inserted = false; if (!empty($options['insertBefore'])) { $inserted = $this->owner->Fields()->insertBefore($field, $options['insertBefore']); } if (!$inserted) { // Add field to end if not added already $this->owner->Fields()->push($field); } } } return $this->owner; } }