Formulário passo a passo Neste exemplo, vamos demonstrar um formulário passo a passo. Este formulário possui um objeto notebook com três páginas. O usuário pode navegar pelas páginas usando botões próximo e anterior. Cada página do notebook possui dois campos. A página 1 tem um botão próximo conectado ao método onStep2(). A página 2 possui dois botões: próximo, conectado ao método onStep1(); e próximo, c...
PD
Formulário passo a passo  
Fechado
Neste exemplo, vamos demonstrar um formulário passo a passo. Este formulário possui um objeto notebook com três páginas. O usuário pode navegar pelas páginas usando botões próximo e anterior. Cada página do notebook possui dois campos. A página 1 tem um botão próximo conectado ao método onStep2(). A página 2 possui dois botões: próximo, conectado ao método onStep1(); e próximo, conectado ao método onStep3(). A última página possuio dois botões: anterior, conectado ao método onStep2(); e "Save", conectado ao método onSavE(). Cada método mantém os dados do formulário e altera a página atual do notebook, por meio do método setCurrentPage() da classe TNotebook. O método onSave() simplesmente exibe os dados do formulário, que irá retornar a informação de todos os seis campos.

 
  1. <?php
  2. /**
  3. * StepbyStepForm report
  4. *
  5. * @version 1.0
  6. * @package samples
  7. * @subpackage tutor
  8. * @author Pablo Dall'Oglio
  9. * @copyright Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10. * @license http://www.adianti.com.br/framework-license
  11. */
  12. class StepbyStepForm extends TPage
  13. {
  14. private $notebook;
  15. private $form;
  16. private $page1;
  17. private $page2;
  18. private $page3;
  19. /**
  20. * Class constructor
  21. * Creates the page and the registration form
  22. */
  23. function __construct()
  24. {
  25. parent::__construct();
  26. // create the notebook
  27. $this->notebook = new TNotebook(340, 100);
  28. // create the form
  29. $this->form = new TForm;
  30. // creates the notebook page
  31. $page1 = new TTable;
  32. $page2 = new TTable;
  33. $page3 = new TTable;
  34. // add the notebook inside the form
  35. $this->form->add($this->notebook);
  36. // adds the notebook page
  37. $this->notebook->appendPage('Page 1', $page1);
  38. $this->notebook->appendPage('Page 2', $page2);
  39. $this->notebook->appendPage('Page 3', $page3);
  40. // create the form fields
  41. $field1 = new TEntry('field1');
  42. $field2 = new TEntry('field2');
  43. $field3 = new TEntry('field3');
  44. $field4 = new TEntry('field4');
  45. $field5 = new TEntry('field5');
  46. $field6 = new TEntry('field6');
  47. // add a row for one field
  48. $row=$page1->addRow();
  49. $row->addCell(new TLabel('Field 1:'));
  50. $cell = $row->addCell( $field1 );
  51. // add a row for one field
  52. $row=$page1->addRow();
  53. $row->addCell(new TLabel('Field 2:'));
  54. $cell = $row->addCell( $field2 );
  55. // creates the action button
  56. $button1=new TButton('action1');
  57. $button1->setAction(new TAction(array($this, 'onStep2')), 'Next');
  58. $button1->setImage('ico_next.png');
  59. $row=$page1->addRow();
  60. $row->addCell( $button1 );
  61. // add a row for one field
  62. $row=$page2->addRow();
  63. $row->addCell(new TLabel('Field 3:'));
  64. $cell = $row->addCell( $field3 );
  65. // add a row for one field
  66. $row=$page2->addRow();
  67. $row->addCell(new TLabel('Field 4:'));
  68. $cell = $row->addCell( $field4 );
  69. // creates the action button
  70. $button2=new TButton('action2');
  71. $button2->setAction(new TAction(array($this, 'onStep1')), 'Previous');
  72. $button2->setImage('ico_previous.png');
  73. $row=$page2->addRow();
  74. $row->addCell( $button2 );
  75. // creates the action button
  76. $button3=new TButton('action3');
  77. $button3->setAction(new TAction(array($this, 'onStep3')), 'Next');
  78. $button3->setImage('ico_next.png');
  79. $row->addCell( $button3 );
  80. // add a row for one field
  81. $row=$page3->addRow();
  82. $row->addCell(new TLabel('Field 5:'));
  83. $cell = $row->addCell( $field5 );
  84. // add a row for one field
  85. $row=$page3->addRow();
  86. $row->addCell(new TLabel('Field 6:'));
  87. $cell = $row->addCell( $field6 );
  88. // creates the action button
  89. $button4=new TButton('action4');
  90. $button4->setAction(new TAction(array($this, 'onStep2')), 'Previous');
  91. $button4->setImage('ico_previous.png');
  92. $row=$page3->addRow();
  93. $row->addCell( $button4 );
  94. $button5=new TButton('save');
  95. $button5->setAction(new TAction(array($this, 'onSave')), 'Save');
  96. $button5->setImage('ico_save.png');
  97. $row->addCell( $button5 );
  98. // define wich are the form fields
  99. $this->form->setFields(array($field1, $field2, $field3, $field4, $field5, $field6, $button1, $button2, $button3, $button4, $button5));
  100. // add the form inside the page
  101. parent::add($this->form);
  102. }
  103. function onStep1()
  104. {
  105. $this->notebook->setCurrentPage(0);
  106. $this->form->setData($this->form->getData());
  107. }
  108. function onStep2()
  109. {
  110. $this->notebook->setCurrentPage(1);
  111. $this->form->setData($this->form->getData());
  112. }
  113. function onStep3()
  114. {
  115. $this->notebook->setCurrentPage(2);
  116. $this->form->setData($this->form->getData());
  117. }
  118. function onSave()
  119. {
  120. $this->notebook->setCurrentPage(2);
  121. $this->form->setData($this->form->getData());
  122. new TMessage('info', json_encode($this->form->getData()));
  123. }
  124. }
  125. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (4)


JG

RS

Olá Pablo,

É possível fazer um formulário do tipo Wizard como este no link abaixo:

authenticgoods.co/wrapbootstrap/themes/neuboard-v1.4.1/HTML_full_ver

?

Abs,
PD

www.adianti.com.br/framework_files/tutor/index.php?class=StaticMulti
PD

Só trocar o CSS