The best IT partner for your business English version

Framework docs

Presentation > Designer > Form elements

More productivity with Adianti Studio Pro

  • Forms designer;
  • Automatic form generation;
  • Automatic datagrid generation;
  • Create DB from your UML;
Ver detalhes...

This sample demonstrates a interface created using Adianti Studio Designer. In this interface we have a form with many kinds of input elements.

The TUIBuilder class is an interface builder. It takes a XML file save by Adianti Studio Designer and renders the form into the interface. The TUIBuilder instance can be added inside any other container like a TNotebook, TTable or directly into TPage controller.

When we put a TUIBuilder inside a TForm object, we need to extract all the fields from the interface through the getFields() method. The result can be passed as parameter for setFields() method from TForm, that will define wich are the form fields.

Important: This samples uses a interface (screen) designed in Adianti Studio Form Designer. Adianti Studio Form Designer is a complete tool that allows the user to draw forms and datagrids with a graphical interface (drag and drop) using the framework components and containers (TEntry, TCombo, TRadioGroup, TFrame, and others. This interface is saved in XML and may be used by the TUIBuilder class, and its parseFile() method to recreate it dynamically during the application execution time.

Click here for
live demonstration

Example

  1. <?php
  2. /**
  3.  * DesignFormView Registration
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class DesignFormView extends TPage
  13. {
  14.     private $form;
  15.     
  16.     /**
  17.      * Class constructor
  18.      * Creates the page and the registration form
  19.      */
  20.     function __construct()
  21.     {
  22.         parent::__construct();
  23.         
  24.         // creates the form
  25.         $this->form = new TForm;
  26.         
  27.         try
  28.         {
  29.             // UIBuilder object
  30.             $ui = new TUIBuilder(500,300);
  31.             $ui->setController($this);
  32.             $ui->setForm($this->form);
  33.             
  34.             // reads the xml form
  35.             $ui->parseFile('app/forms/sample.form.xml');
  36.             
  37.             // add the TUIBuilder panel inside the form
  38.             $this->form->add($ui);
  39.             
  40.             // set the form fields from the interface
  41.             $this->form->setFields($ui->getFields());
  42.         }
  43.         catch (Exception $e)
  44.         {
  45.             new TMessage('error'$e->getMessage());
  46.         }
  47.         
  48.         // wrap the page content using vertical box
  49.         $vbox = new TVBox;
  50.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  51.         $vbox->add($this->form);
  52.         parent::add($vbox);
  53.     }
  54.     
  55.     /**
  56.      * method onView()
  57.      * Executed whenever the user clicks at the save button
  58.      */
  59.     function onView()
  60.     {
  61.         try
  62.         {
  63.             $data $this->form->getData(); // optional parameter: active record class
  64.             
  65.             // put the data back to the form
  66.             $this->form->setData($data);
  67.             
  68.             $this->form->validate();
  69.             
  70.             // creates a string with the form element's values
  71.             $message 'ID : ' $data->id '<br>';
  72.             $message.= 'Name : ' $data->name '<br>';
  73.             $message.= 'Birthdate : ' $data->birthdate '<br>';
  74.             $message.= 'Gender : ' $data->gender '<br>';
  75.             $message.= 'Pets : ' $data->pets '<br>';
  76.             $message.= 'Income : ' $data->income '<br>';
  77.             $message.= 'Weight : ' $data->weight '<br>';
  78.             $message.= 'Fashion : ' implode(','$data->fashion) . '<br>';  
  79.             
  80.             // show the message
  81.             new TMessage('info'$message);
  82.         }
  83.         catch(Exception $e)
  84.         {
  85.             new TMessage('error'$e->getMessage());
  86.         }
  87.     }
  88. }
  89. ?>