Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Application_Form_ContactForm extends Zend_Form
- {
- public function __construct($options = null)
- {
- parent::__construct($options);
- $this->setName('envia_sms')
- ->setMethod('get');
- $username = new Zend_Form_Element_Hidden("username");
- $username->setValue("blah");
- $password = new Zend_Form_Element_Hidden('password');
- $password->setValue('bleh');
- $number = new Zend_Form_Element_Text('to');
- $number->setLabel('Numero')
- ->setRequired(true)
- ->addValidator('NotEmpty')
- ->addValidator('Digits');
- $message = new Zend_Form_Element_Textarea('text');
- $message->setLabel('Mensagem')
- ->setRequired(true)
- ->addValidator('NotEmpty')
- ->addValidator('StringLength', false, array(0,160));
- $submit = new Zend_Form_Element_Submit('submit');
- $submit->setLabel('Enviar SMS');
- $this->addElements(array($username, $password, $number, $message, $submit));
- }
- }
- ------ Controller ------
- class IndexController extends Zend_Controller_Action
- {
- public function init()
- {
- /* Initialize action controller here */
- }
- public function indexAction()
- {
- $this->view->pageTitle = "Zend_Form Example";
- $this->view->bodyCopy = "<p >Please fill out this form.</p>";
- $form = new Application_Form_ContactForm();
- $data = array( 'username'=> 'bleh' );
- $form->populate( $data );
- if ($this->_request->isGet()) {
- $formData = $this->_request->getQuery();
- if ($form->isValid($formData)) {
- echo 'success';
- exit;
- } else {
- $form->populate($formData);
- }
- }
- $this->view->form = $form;
- }
- }
- ----------------------- OUTPUT ------------------------
- Zend_Form Example<p >Please fill out this form.</p>
- <form id="envia_sms" enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form">
- <dt id="username-label"> </dt>
- <dd id="username-element">
- <input type="hidden" name="username" value="" id="username"></dd>
- <dt id="password-label"> </dt>
- <dd id="password-element">
- <input type="hidden" name="password" value="" id="password"></dd>
- <dt id="to-label"><label for="to" class="required">Numero</label></dt>
- <dd id="to-element">
- <input type="text" name="to" id="to" value="">
- <ul class="errors"><li>Value is required and can't be empty</li><li>Invalid type given, value should be string, integer or float</li></ul></dd>
- <dt id="text-label"><label for="text" class="required">Mensagem</label></dt>
- <dd id="text-element">
- <textarea name="text" id="text" rows="24" cols="80"></textarea>
- <ul class="errors"><li>Value is required and can't be empty</li><li>Invalid type given, value should be a string</li></ul></dd>
- <dt id="submit-label"> </dt><dd id="submit-element">
- <input type="submit" name="submit" id="submit" value="Enviar SMS"></dd></dl></form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement