Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZF]Jak przepisać kod HTML dla formularza do Zend_Form
amii
post
Post #1





Grupa: Zarejestrowani
Postów: 728
Pomógł: 76
Dołączył: 12.06.2009

Ostrzeżenie: (0%)
-----


Mam tak kod HTML odpowiadający za formularz logowania:
  1. <form action="<?php echo $this->url(array('module' => 'user', 'controller' => 'index', 'action' => 'login')) ?>" method="post" name="loginbox" id="loginbox">
  2.  
  3. <?php echo '<img alt="" src="img/input-left.png" height="28" width="14">'; ?><input class="input" onfocus="this.value='';" onblur="if(this.value==''){this.value='Twój login';}" size="20" id="konto_login_inputl" name="konto_login_input" value="Twój login" type="text"><?php echo '<img alt="" src="img/input-right.png" height="28" width="14">&nbsp;&nbsp;'; ?>
  4.  
  5.  
  6. <?php echo '<img alt="" src="img/input-left.png" height="28" width="14">'; ?><input class="input" onfocus="this.value='';this.type='password';" onblur="if(this.value==''){this.value='Has\u0142o';this.type='text';}" size="20" id="password_login_input" name="password_login_input" value="Hasło" type="password"><?php echo '<img alt="" src="img/input-right.png" height="28" width="14">'; ?> &nbsp;&nbsp;
  7.  
  8.  
  9. <?php echo '<input src="img/btn-arrow-right.png" name="submit" alt="Zaloguj!" type="image">'; ?>
  10. </form>


Nie mam pomysłu jak przepisać do Zend_Form funkcje JS i zdjęcia. Na razie mam coś takiego:


  1. class User_Form_Login extends Zend_Form {
  2.  
  3. public function init() {
  4. $this->addElementPrefixPath('Suuper_Validators_', 'Suuper/Validators', 'validate');
  5. $this->addPrefixPath('Suuper_Form_Element_', 'Suuper/Form/Element', Zend_Form::ELEMENT);
  6. $this->addHead();
  7. $this->addFields();
  8. }
  9.  
  10. private function addHead() {
  11. $this->setAction($this->getView()->url(array('module' => 'user',
  12. 'controller' => 'index', 'action' => 'login'), 'default', false))
  13. ->setMethod('post')
  14. ->setAttribs(array('id'=>'userLoginForm',
  15. 'class'=>'zend'));
  16. }
  17. private function addFields() {
  18.  
  19. //konto
  20. $konto=new Suuper_Form_Element_Text('konto_login_input', array(
  21. 'id' => 'konto_login_input',
  22. 'maxlength' => '20',
  23. 'required' => true
  24. ));
  25. $konto->setAttrib('class', 'input');
  26. $this->addElement($konto);
  27.  
  28.  
  29. //password
  30. $password=new Suuper_Form_Element_Password('password_login_input', array(
  31. 'id' => 'password_login_input',
  32. 'maxlength' => '14',
  33. 'required' => true
  34. ));
  35. $password->setAttrib('class', 'input');
  36. $this->addElement($password);
  37.  
  38.  
  39.  
  40. $bs = $this->createElement('submit', 'btnSubmit');
  41. $bs->setAttrib('src', 'img/btn-arrow-right.png');
  42. $bs->setAttrib('alt', 'Zaloguj!');
  43. $this->addElement($bs);
  44. }
  45.  
  46. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
doogi
post
Post #2





Grupa: Zarejestrowani
Postów: 12
Pomógł: 5
Dołączył: 9.04.2008

Ostrzeżenie: (0%)
-----


Jednym z rozwiązań jest zdefiniowanie w konstruktorze Twojej klasy User_Form_Login dekoratora ViewScript:
  1. $this->setDecorators(array(
  2. array('ViewScript', array('viewScript' => 'forms/loginForm.phtml'))
  3. ));

gdzie podajesz ścieżkę do pliku widoku całego formularza (oczywiście domyślnie ścieżka względna od katalogu z innymi skryptami widoków w aplikacji). Przykładowy plik tego widoku może wyglądać następująco:
  1. <form id="<?php echo $this->element->getName(); ?>" action="<?php echo $this->element->getAction(); ?>" method="<?php echo $this->element->getMethod(); ?>">
  2. <dl>
  3. <?php echo $this->element->username; ?>
  4. <?php echo $this->element->password; ?>
  5. <?php echo $this->element->login; ?>
  6. <?php echo $this->element->csrf; ?>
  7. </dl>
  8. </form>

Tudzież może wzbogacić go o co tych chcesz (IMG:style_emoticons/default/wink.gif)

Dodatkowa dokumentacja na temat dekoratora ViewScript tutaj

Ten post edytował doogi 31.08.2011, 10:57:28
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 11:33