2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class Syj_Form_Contact extends Zend_Form
8 protected $_decorators = array(
9 'FormElements' => array('decorator' => 'FormElements', 'options' => null),
10 'Form' => array('decorator' => 'Form', 'options' => array()));
12 protected $_elementDecorators = array(
14 'Errors' => array('decorator' => 'Errors', 'options' => array('class' => 'error')),
15 array(array('lbreak1' => 'HtmlTag'), array('tag' => 'br', 'openOnly' => true)),
17 array(array('lbreak2' => 'HtmlTag'), array('tag' => 'br', 'placement' => 'APPEND', 'openOnly' => true)),
20 public function init() {
21 $formErrors = $this->getView()->getHelper('FormErrors');
22 $formErrors->setElementStart("<div%s>")
23 ->setElementEnd("</div>")
24 ->setElementSeparator("<br>");
26 // required needs following string to be translated
27 __("Value is required and can't be empty");
29 // we are less strict than Zend_Validate_Email because we want a user
30 // with a strange email to be able to still contact us with the form
31 $emailValidator = new Zend_Validate_Regex('/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i');
32 $emailValidator->setMessage(__("Invalid email"), $emailValidator::NOT_MATCH);
33 $email = array('Text', 'contact_email', array(
35 'validators' => array($emailValidator),
36 'label' => __("Email:")));
39 $subjectValidator = new Zend_Validate_StringLength(0, $maxSubjLength);
40 $subjectValidator->setMessage(__("Subject must be %max% characters long or less",$subjectValidator::TOO_LONG));
41 $subject = array('Text', 'contact_subject', array(
43 'maxlength' => $maxSubjLength,
44 'validators' => array($subjectValidator),
45 'label' => __("Subject:")));
47 $contentFilter = new Zend_Filter_PregReplace('/\r\n/', "\n");
48 $content = array('Textarea', 'contact_content', array(
49 'label' => __("Message:"),
51 'filters' => array($contentFilter),
55 $submit = array('Submit', 'contact_submit', array(
56 'label' => __("Send"),
57 'decorators' => array('ViewHelper')));
59 $this->addElements(array($email, $subject, $content, $submit));
61 // fieldset around form
62 $this->addDisplayGroup(array_keys($this->_elements), 'main',
63 array('decorators' => array('FormElements',
64 array('fieldset', array('legend' => __("Send a message")))