Created
December 19, 2011 07:54
-
-
Save enricofoltran/1495973 to your computer and use it in GitHub Desktop.
Contact form with Zend Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* /library/Square/Form/Contact.php */ | |
class Square_Form_Contact extends Zend_Form | |
{ | |
public function init() | |
{ | |
$this->setAction('/contact') | |
->setMethod('post'); | |
$name = new Zend_Form_Element_Text('name'); | |
$name->setLabel('Name:') | |
->setOptions(array('size' => '35')) | |
->setRequired(true) | |
->addValidator('NotEmpty', true) | |
->addValidator('Alpha', true, array('allowWhiteSpace' => true)) | |
->addFilter('HtmlEntities') | |
->addFilter('StringTrim'); | |
$email = new Zend_form_Element_Text('email'); | |
$email->setLabel('Email address:') | |
->setRequired(true) | |
->addValidator('NotEmpty', true) | |
->addValidator('EmailAddress', true) | |
->addFilter('HtmlEntities') | |
->addFilter('StringToLower') | |
->addFilter('StringTrim'); | |
$message = new Zend_Form_Element_Textarea('message'); | |
$message->setLabel('Message:') | |
->setOptions(array('rows' => '8', 'cols' => '40')) | |
->setRequired(true) | |
->addValidator('NotEmpty', true) | |
->addFilter('HtmlEntities') | |
->addFilter('StringTrim'); | |
$captcha = new Zend_Form_Element_Captcha('captcha', array( | |
'captcha' => array( | |
'captcha' => 'Image', | |
'wordLen' => 6, | |
'timeout' => 300, | |
'width' => 300, | |
'height' => 100, | |
'imgUrl' => '/assets/captcha', | |
'imgDir' => APPLICATION_PATH . '/../public/assets/captcha', | |
'font' => APPLICATION_PATH . '/../public/assets/fonts/LiberationSansRegular.ttf' | |
)) | |
); | |
$captcha->setLabel('Verification code:'); | |
$submit = new Zend_Form_Element_Submit('submit'); | |
$submit->setLabel('Send Message') | |
->setOptions(array('class' => 'submit')); | |
$this->addElement($name) | |
->addElement($email) | |
->addElement($message) | |
->addElement($captcha) | |
->addElement($submit); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment