From cbe2fa31716e830bbb8e8516c45249450cccf967 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Tue, 17 Feb 2009 09:03:59 +0000 Subject: [PATCH] ENHANCEMENT:update_form returns null if the spam protection field create fails --- INSTALL | 2 +- code/SpamProtecterManager.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/INSTALL b/INSTALL index b8fe335..790f5d8 100644 --- a/INSTALL +++ b/INSTALL @@ -40,7 +40,7 @@ This following code should appear after the form creation. <<<< CODE STARTS >>>> -$protectorField = SpamProtecterManager::update_form('MollomField', 'Captcha', $form, 'Message', $callbackObj); +$protector = SpamProtecterManager::update_form('MollomField', 'Captcha', $form, 'Message', $callbackObj); <<<< CODE ENDS >>>> diff --git a/code/SpamProtecterManager.php b/code/SpamProtecterManager.php index 8ae8b23..49d5988 100644 --- a/code/SpamProtecterManager.php +++ b/code/SpamProtecterManager.php @@ -27,12 +27,17 @@ class SpamProtecterManager { * and a string of field names (seperated by comma) as a value. * The naming of the fields is based on the implementation of the subclass of SpamProtecterField. * *** Most of the web service doesn't require this. - * @return SpamProtector object + * @return SpamProtector object or return null if the spamprotecter class is not found + * or spamprotecterfield creation fails. */ static function update_form($form, $before=null, $callbackObject=null, $fieldsToSpamServiceMapping=null) { + if (!class_exists(self::$spam_protecter)) return null; + $protecter = new self::$spam_protecter(); - - $protecter->updateForm($form, $before, $callbackObject, $fieldsToSpamServiceMapping); + $check = $protecter->updateForm($form, $before, $callbackObject, $fieldsToSpamServiceMapping); + + if (!$check) return null; + return $protecter; }