Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.42 KB | None | 0 0
  1. class Application_Form_ContactForm extends Zend_Form
  2. {
  3.         public function __construct($options = null)
  4.         {
  5.                 parent::__construct($options);
  6.                 $this->setName('envia_sms')
  7.             ->setMethod('get');
  8.  
  9.                 $username = new Zend_Form_Element_Hidden("username");
  10.                 $username->setValue("blah");
  11.  
  12.                 $password = new Zend_Form_Element_Hidden('password');
  13.                 $password->setValue('bleh');
  14.  
  15.                 $number = new Zend_Form_Element_Text('to');
  16.                 $number->setLabel('Numero')
  17.                         ->setRequired(true)
  18.                         ->addValidator('NotEmpty')
  19.                         ->addValidator('Digits');
  20.  
  21.                 $message = new Zend_Form_Element_Textarea('text');
  22.                 $message->setLabel('Mensagem')
  23.                         ->setRequired(true)
  24.                         ->addValidator('NotEmpty')
  25.                         ->addValidator('StringLength', false, array(0,160));
  26.  
  27.                 $submit = new Zend_Form_Element_Submit('submit');
  28.                 $submit->setLabel('Enviar SMS');
  29.  
  30.                 $this->addElements(array($username, $password, $number, $message, $submit));
  31.  
  32.         }
  33. }
  34.  
  35.  
  36. ------ Controller ------
  37.  
  38.  
  39. class IndexController extends Zend_Controller_Action
  40. {
  41.  
  42.         public function init()
  43.         {
  44.                 /* Initialize action controller here */
  45.         }
  46.  
  47.         public function indexAction()
  48.         {
  49.                 $this->view->pageTitle = "Zend_Form Example";
  50.                 $this->view->bodyCopy = "<p >Please fill out this form.</p>";
  51.  
  52.                 $form = new Application_Form_ContactForm();
  53.                 $data = array( 'username'=> 'bleh' );
  54.                 $form->populate( $data );
  55.  
  56.                 if ($this->_request->isGet()) {
  57.                         $formData = $this->_request->getQuery();
  58.                         if ($form->isValid($formData)) {
  59.                                 echo 'success';
  60.                                 exit;
  61.                         } else {
  62.                                 $form->populate($formData);
  63.                         }
  64.                 }
  65.  
  66.                 $this->view->form = $form;
  67.         }
  68.  
  69.  
  70. }
  71.  
  72. ----------------------- OUTPUT ------------------------
  73.  
  74.  
  75. Zend_Form Example<p >Please fill out this form.</p>
  76. <form id="envia_sms" enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form">
  77. <dt id="username-label">&#160;</dt>
  78. <dd id="username-element">
  79. <input type="hidden" name="username" value="" id="username"></dd>
  80. <dt id="password-label">&#160;</dt>
  81. <dd id="password-element">
  82. <input type="hidden" name="password" value="" id="password"></dd>
  83. <dt id="to-label"><label for="to" class="required">Numero</label></dt>
  84. <dd id="to-element">
  85. <input type="text" name="to" id="to" value="">
  86. <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>
  87.  
  88. <dt id="text-label"><label for="text" class="required">Mensagem</label></dt>
  89. <dd id="text-element">
  90. <textarea name="text" id="text" rows="24" cols="80"></textarea>
  91. <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>
  92. <dt id="submit-label">&#160;</dt><dd id="submit-element">
  93. <input type="submit" name="submit" id="submit" value="Enviar SMS"></dd></dl></form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement