* @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() { $this->addConfigAsGlobalVars(); 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']); $this->injectElement4Captcha($list, $this->user->isAuthenticated(), $this->config['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 getFormRuleList($name) { return parent::getFormRuleList($this->config['form']); } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'contact'; } }