Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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.     /**
  21.      * Class constructor
  22.      * Creates the page and the registration form
  23.      */
  24.     function __construct()
  25.     {
  26.         parent::__construct();
  27.         
  28.         // create the notebook
  29.         $this->notebook = new TNotebook(340100);
  30.         
  31.         // create the form
  32.         $this->form = new TForm;
  33.         
  34.         // creates the notebook page
  35.         $page1 = new TTable;
  36.         $page2 = new TTable;
  37.         $page3 = new TTable;
  38.         
  39.         // add the notebook inside the form
  40.         $this->form->add($this->notebook);
  41.         
  42.         // adds the notebook page
  43.         $this->notebook->appendPage('Page 1'$page1);
  44.         $this->notebook->appendPage('Page 2'$page2);
  45.         $this->notebook->appendPage('Page 3'$page3);
  46.         
  47.         // create the form fields
  48.         $field1 = new TEntry('field1');
  49.         $field2 = new TEntry('field2');
  50.         $field3 = new TEntry('field3');
  51.         $field4 = new TEntry('field4');
  52.         $field5 = new TEntry('field5');
  53.         $field6 = new TEntry('field6');
  54.         
  55.         // add a row for one field
  56.         $row=$page1->addRow();
  57.         $row->addCell(new TLabel('Field 1:'));
  58.         $cell $row->addCell$field1 );
  59.         
  60.         // add a row for one field
  61.         $row=$page1->addRow();
  62.         $row->addCell(new TLabel('Field 2:'));
  63.         $cell $row->addCell$field2 );
  64.         
  65.         // creates the action button
  66.         $button1=new TButton('action1');
  67.         $button1->setAction(new TAction(array($this'onStep2')), 'Next');
  68.         $button1->setImage('ico_next.png');
  69.         $row=$page1->addRow();
  70.         $row->addCell$button1 );
  71.         
  72.         // add a row for one field
  73.         $row=$page2->addRow();
  74.         $row->addCell(new TLabel('Field 3:'));
  75.         $cell $row->addCell$field3 );
  76.         
  77.         // add a row for one field
  78.         $row=$page2->addRow();
  79.         $row->addCell(new TLabel('Field 4:'));
  80.         $cell $row->addCell$field4 );
  81.         
  82.         // creates the action button
  83.         $button2=new TButton('action2');
  84.         $button2->setAction(new TAction(array($this'onStep1')), 'Previous');
  85.         $button2->setImage('ico_previous.png');
  86.         $row=$page2->addRow();
  87.         $row->addCell$button2 );
  88.         
  89.         // creates the action button
  90.         $button3=new TButton('action3');
  91.         $button3->setAction(new TAction(array($this'onStep3')), 'Next');
  92.         $button3->setImage('ico_next.png');
  93.         $row->addCell$button3 );
  94.         
  95.         // add a row for one field
  96.         $row=$page3->addRow();
  97.         $row->addCell(new TLabel('Field 5:'));
  98.         $cell $row->addCell$field5 );
  99.         
  100.         // add a row for one field
  101.         $row=$page3->addRow();
  102.         $row->addCell(new TLabel('Field 6:'));
  103.         $cell $row->addCell$field6 );
  104.         
  105.         // creates the action button
  106.         $button4=new TButton('action4');
  107.         $button4->setAction(new TAction(array($this'onStep2')), 'Previous');
  108.         $button4->setImage('ico_previous.png');
  109.         $row=$page3->addRow();
  110.         $row->addCell$button4 );
  111.         
  112.         $button5=new TButton('save');
  113.         $button5->setAction(new TAction(array($this'onSave')), 'Save');
  114.         $button5->setImage('ico_save.png');
  115.         $row->addCell$button5 );
  116.         
  117.         // define wich are the form fields
  118.         $this->form->setFields(array($field1$field2$field3$field4$field5$field6$button1$button2$button3$button4$button5));
  119.         
  120.         // add the form inside the page
  121.         parent::add($this->form);
  122.     }
  123.     
  124.     function onStep1()
  125.     {
  126.         $this->notebook->setCurrentPage(0);
  127.         $this->form->setData($this->form->getData());
  128.     }
  129.     
  130.     function onStep2()
  131.     {
  132.         $this->notebook->setCurrentPage(1);
  133.         $this->form->setData($this->form->getData());
  134.     }
  135.     
  136.     function onStep3()
  137.     {
  138.         $this->notebook->setCurrentPage(2);
  139.         $this->form->setData($this->form->getData());
  140.     }
  141.     
  142.     function onSave()
  143.     {
  144.         $this->notebook->setCurrentPage(2);
  145.         $this->form->setData($this->form->getData());
  146.         new TMessage('info'json_encode($this->form->getData()));
  147.     }
  148. }
  149. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto 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