* @license PHP License * @package WB * @subpackage content */ /** * Load base class */ WBClass::load('WBContent'); /** * Content component: ContactForm * * Quite simple component that displays a form and validates user input * and fires event in case form could be validated * * @version 0.3.0 * @package WB * @subpackage content * @todo implement requiregroup! */ class WBContent_ContactForm extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'form' => 'brief', 'captcha' => 'auto', 'requiredgroup' => parent::GROUP_ANON, ); /** * run * * run component * * @return array parameter list */ public function run() { if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('accessDenied'); return $this->config; } // mangle template folder $tmplDir = $this->config['tmplDir']; $this->config['tmplDir'] = $tmplDir . '/' . $this->config['form']; $this->processForm('form'); // reset template folder $this->config['tmplDir'] = $tmplDir; return $this->config; } /** * receive output * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate( 'snippet' ); } /** * Validation completed * * Trigger event on valid form * * @param patForms $form * @param array $values */ public function onFormValid($form, $values) { $values['form'] = $this->config['form']; $values['user'] = $this->user->getId(); $values['created'] = gmdate('Y-m-d H:i:s'); WBEvent::trigger('contactform:valid:' . $values['form'], 'Contact form validated', $values); return true; } /** * Fetch list of form elements * * Use different file regardless of actual form name. * * @param string name of form * @return array $elements */ protected function getFormElementList($name) { $list = parent::getFormElementList($this->config['form']); // add captcha element in case user is not logged in right now if ($this->config['captcha'] == 'auto' && !$this->user->isAuthenticated()) { $list['captcha'] = array( 'type' => 'String', 'attributes' => array( 'title' => patI18n::dgettext('wombat', 'CAPTCHA'), 'label' => patI18n::dgettext('wombat', 'CAPTCHA'), 'description' => patI18n::dgettext('wombat', 'Please type in what the picture shows.'), 'class' => 'field captcha', 'minlength' => 3, 'maxlength' => 255, ), 'rule' => array('Captcha') ); } // copy default values from user data if ($this->user->isAuthenticated()) { $userData = $this->user->getData(); foreach ($userData as $key => $values) { if (!isset($list[$key])) { continue; } $list[$key]['attributes']['default'] = $userData[$key]; } } return $list; } /** * Fetch list of form elements * * Use different file regardless of actual form name. * * @param string name of form * @return array $elements */ protected function getFormRuletList($name) { return parent::getFormRuletList($this->config['form']); } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'contact'; } } ?>