Skip to content

Instantly share code, notes, and snippets.

@enricofoltran
Created December 19, 2011 07:54
Show Gist options
  • Save enricofoltran/1495973 to your computer and use it in GitHub Desktop.
Save enricofoltran/1495973 to your computer and use it in GitHub Desktop.
Contact form with Zend Framework
<?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