The best IT partner for your business English version

Framework docs

Organization > Designed views > Form

More productivity with Adianti Studio Pro

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

This sample demonstrates how to use a form completely created by Adianti Studio Form Designer. In the constructor method of the page controller, the TUIBuilder class parses the XML containing the form, define the controller and define the form fields based on the extracted fields from the interface.

The form has the save button, that is connected to the onSave(). This method takes the form data as a Customer Active Record, and stores the Active Record object in the database.

The onEdit() method is called from the "new" button or from an external datagrid controller, in this case by DesignedDataGridView class, identifying the record to be edited through the key parameter. The onEdit() method loads the Active Record identified by the key parameter into memory.

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.  * DesignedFormView 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 DesignedFormView 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('form_Customer');
  26.         
  27.         try
  28.         {
  29.             // TUIBuilder object
  30.             $ui = new TUIBuilder(500460);
  31.             $ui->setController($this);
  32.             $ui->setForm($this->form);
  33.             
  34.             // reads the xml form
  35.             $ui->parseFile('app/forms/customer.form.xml');
  36.             // add the TUIBuilder panel inside the TForm object
  37.             $this->form->add($ui);
  38.             // define the form fields from interface fields
  39.             $this->form->setFields($ui->getFields());
  40.         }
  41.         catch (Exception $e)
  42.         {
  43.             new TMessage('error'$e->getMessage());
  44.         }
  45.         
  46.         // wrap the page content using vertical box
  47.         $vbox = new TVBox;
  48.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  49.         $vbox->add($this->form);
  50.         parent::add($vbox);
  51.     }
  52.     
  53.     /**
  54.      * method onSave()
  55.      * Executed whenever the user clicks at the save button
  56.      */
  57.     function onSave()
  58.     {
  59.         try
  60.         {
  61.             // open a transaction with database 'samples'
  62.             TTransaction::open('samples');
  63.             // get the form data into an active record {active_record}
  64.             $object $this->form->getData('Customer');
  65.             
  66.             // stores the object
  67.             $object->store();
  68.             
  69.             // set the data back to the form
  70.             $this->form->setData($object);
  71.             
  72.             // close the transaction
  73.             TTransaction::close();
  74.             // shows the success message
  75.             new TMessage('info''Record saved');
  76.             // reload the listing
  77.         }
  78.         catch (Exception $e// in case of exception
  79.         {
  80.             // shows the exception error message
  81.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  82.             // undo all pending operations
  83.             TTransaction::rollback();
  84.         }
  85.     }
  86.     
  87.     /**
  88.      * method onEdit()
  89.      * Executed whenever the user clicks at the edit button da datagrid
  90.      */
  91.     function onEdit($param)
  92.     {
  93.         try
  94.         {
  95.             if (isset($param['key']))
  96.             {
  97.                 // get the parameter $key
  98.                 $key=$param['key'];
  99.                 
  100.                 // open a transaction with database 'samples'
  101.                 TTransaction::open('samples');
  102.                 
  103.                 // instantiates object Customer
  104.                 $object = new Customer($key);
  105.                 
  106.                 // fill the form with the active record data
  107.                 $this->form->setData($object);
  108.                 
  109.                 // close the transaction
  110.                 TTransaction::close();
  111.             }
  112.             else
  113.             {
  114.                 $this->form->clear();
  115.             }
  116.         }
  117.         catch (Exception $e// in case of exception
  118.         {
  119.             // shows the exception error message
  120.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  121.             // undo all pending operations
  122.             TTransaction::rollback();
  123.         }
  124.     }
  125. }
  126. ?>