]> dev.renevier.net Git - syj.git/blob - application/forms/Contact.php
version 0.1
[syj.git] / application / forms / Contact.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class Syj_Form_Contact extends Zend_Form
6 {
7
8     protected $_decorators = array(
9                             'FormElements' => array('decorator' => 'FormElements', 'options' => null),
10                             'Form' => array('decorator' => 'Form', 'options' => array()));
11
12     protected $_elementDecorators = array(
13                                 'ViewHelper',
14                                 'Errors' => array('decorator' => 'Errors', 'options' => array('class' => 'error')),
15                                 array(array('lbreak1' => 'HtmlTag'), array('tag' => 'br', 'openOnly' => true)),
16                                 'Label',
17                                 array(array('lbreak2' => 'HtmlTag'), array('tag' => 'br', 'placement' => 'APPEND', 'openOnly' => true)),
18                                 );
19
20     public function init() {
21         $formErrors = $this->getView()->getHelper('FormErrors');
22         $formErrors->setElementStart("<div%s>")
23                    ->setElementEnd("</div>")
24                    ->setElementSeparator("<br>");
25
26         // required needs following string to be translated
27         __("Value is required and can't be empty");
28
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(
34              'required' => 'true',
35              'validators' => array($emailValidator),
36             'label' => __("Email:")));
37
38         $maxSubjLength = 80;
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(
42              'required' => 'true',
43              'maxlength' => $maxSubjLength,
44              'validators' => array($subjectValidator),
45             'label' => __("Subject:")));
46
47         $contentFilter = new Zend_Filter_PregReplace('/\r\n/', "\n");
48         $content = array('Textarea', 'contact_content', array(
49             'label' => __("Message:"),
50             'cols' => 40,
51             'filters' => array($contentFilter),
52             'required' => 'true',
53             'rows' => 10));
54
55         $submit = array('Submit', 'contact_submit', array(
56             'label' => __("Send"),
57             'decorators' => array('ViewHelper')));
58
59         $this->addElements(array($email, $subject, $content, $submit));
60
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")))
65         )));
66     }
67
68 }