create($protector); } } else { $protector = Config::inst()->get('FormSpamProtectionExtension', 'default_spam_protector'); $protector = Injector::inst()->create($protector); } // captcha form field name (must be unique) if(isset($options['name'])) { $name = $options['name']; } else { $name = 'Captcha'; } // captcha field title if(isset($options['title'])) { $title = $options['title']; } else { $title = ''; } // set custom mapping on this form if(isset($options['mapping'])) { $this->fieldMapping = $options['mapping']; } // add the form field if($field = $protector->getFormField($name, $title)) { $this->owner->Fields()->push($field); } return $this->owner; } /** * @return bool */ public function hasSpamProtectionMapping() { return ($this->fieldMapping); } /** * @return array */ public function getSpamMappedData() { if($this->fieldMapping) { $result = array(); $data = $this->owner->getData(); foreach($this->fieldMapping as $fieldName => $mappedName) { $result[$mappedName] = (isset($data[$fieldName])) ? $data[$fieldName] : null; } return $result; } return null; } }