Guest User

Untitled

a guest
Sep 4th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. Zend framework form Decorators
  2. <form action="/index/login" method="post" id="login_form">
  3. <div class="input_row">
  4. <img src="/images/user_icon.png" class="login_icon" alt=""/>
  5. <label for="username" class="login_label">Username:</label>
  6. <input type="text" name="username" value="" id="username" class="login_input" />
  7. </div>
  8. <div class="input_row">
  9. <img src="/images/password_icon.png" class="login_icon" alt=""/>
  10. <label for="password" class="login_label">Password:</label>
  11. <input type="password" name="password" value="" id="password" class="login_input" />
  12. </div>
  13. <div class="input_row">
  14. <input type="submit" name="login_submit" value="Login" class="login_submit" />
  15. </div>
  16. </form>
  17.  
  18. $form = new Zend_Form;
  19.  
  20. $form->setAction('/index/login')
  21. ->setMethod('post')
  22. ->setAttrib('id', 'login_form');
  23.  
  24. $username = $form->createElement('text', 'username');
  25. $username->addValidator('alnum')
  26. ->setRequired(TRUE)
  27. ->setLabel('Username')
  28. ->setAttrib('class', 'login_input');
  29.  
  30.  
  31. $username->setDecorators(array(
  32. 'ViewHelper',
  33. 'Errors',
  34. array('Label',array('class' => 'login_label')),
  35. array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'input_row')
  36. ));
  37.  
  38.  
  39. $form->addElement($username)
  40. ->addElement('submit', 'login', array('label' => 'Login'));
  41.  
  42. $form = new Zend_Form;
  43.  
  44. $form->removeDecorator('htmlTag');
  45.  
  46. $form->setAction('/index/login')
  47. ->setMethod('post')
  48. ->setAttrib('id', 'login_form');
  49.  
  50. $username = $form->createElement('text', 'username');
  51.  
  52. $username->addValidator('alnum')
  53. ->setRequired(TRUE)
  54. ->setLabel('Username')
  55. ->setAttrib('class', 'login_input');
  56.  
  57.  
  58. // anonymous function that will generate your image tag
  59. $makeImg = function($content, $element, array $options) {
  60. return '<img src="/images/' . $options['img'] . '" class="' . $options['class'] . ' " alt=""/> ';
  61. };
  62.  
  63.  
  64. $username->setDecorators(array(
  65. 'ViewHelper',
  66. 'Errors',
  67. array('Label', array('class' => 'login_label')),
  68. array('Callback',
  69. array(
  70. 'callback' => $makeImg,
  71. 'img' => 'user_icon.png',
  72. 'class' => 'login_icon',
  73. 'placement' => 'PREPEND'
  74. )
  75. ),
  76. array('HtmlTag', array('tag' => null, 'class' => 'input_row')),
  77. ));
  78.  
  79. $form->addElement($username);
  80.  
  81.  
  82. $submit = $form->createElement('submit', 'login', array(
  83. 'label' => 'Login',
  84. 'class' => 'login_submit'
  85. )
  86. );
  87.  
  88.  
  89. $submit->setDecorators(array(
  90. 'ViewHelper',
  91. 'Errors',
  92. array('HtmlTag', array('tag' => null, 'class' => 'input_row')),
  93. ));
  94.  
  95. $form->addElement($submit);
  96.  
  97. <form id="login_form" enctype="application/x-www-form-urlencoded" action="/index/login" method="post">
  98. <div class="input_row">
  99. <img src="/images/user_icon.png" class="login_icon " alt="">
  100. <label for="username" class="login_label required">Username</label>
  101. <input type="text" name="username" id="username" value="" class="login_input">
  102. </div>
  103. <div class="input_row">
  104. <input type="submit" name="login" id="login" value="Login" class="login_submit">
  105. </div>
  106. </form>
Add Comment
Please, Sign In to add comment