SHARE
TWEET

Untitled

a guest Jan 14th, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * FormBuilderView
  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 FormBuilderView extends TPage
  13. {
  14.     private $form;
  15.    
  16.     /**
  17.      * Class constructor
  18.      * Creates the page
  19.      */
  20.     function __construct()
  21.     {
  22.         parent::__construct();
  23.        
  24.         // create the form
  25.         $this->form = new BootstrapFormBuilder;
  26.         $this->form->setFormTitle(_t('Bootstrap form'));
  27.         $this->form->generateAria(); // automatic aria-label
  28.        
  29.         // create the form fields
  30.         $id          = new TEntry('id');
  31.         $description = new TEntry('description');
  32.         $password    = new TPassword('password');
  33.         $created     = new TDateTime('created');
  34.         $expires     = new TDate('expires');
  35.         $value       = new TEntry('value');
  36.         $color       = new TColor('color');
  37.         $weight      = new TSpinner('weight');
  38.         $type        = new TCombo('type');
  39.         $text        = new TText('text');
  40.        
  41.         $expires->setExitAction(new TAction([$this, 'onExitExpires']));
  42.        
  43.         $id->setEditable(FALSE);
  44.         $created->setMask('dd/mm/yyyy hh:ii');
  45.         $expires->setMask('dd/mm/yyyy');
  46.         $created->setDatabaseMask('yyyy-mm-dd hh:ii');
  47.         $expires->setDatabaseMask('yyyy-mm-dd');
  48.         $value->setNumericMask(2, ',', '.', true);
  49.         $value->setSize('100%');
  50.         $color->setSize('100%');
  51.         $created->setSize('100%');
  52.         $expires->setSize('100%');
  53.         $weight->setRange(1,100,0.1);
  54.         $weight->setSize('100%');
  55.         $type->setSize('100%');
  56.         $type->addItems( ['a' => 'Type a', 'b' => 'Type b', 'c' => 'Type c'] );
  57.        
  58.         // disable dates (bootstrap date picker)
  59.         $expires->setOption('datesDisabled', [ "23/02/2019", "24/02/2019", "25/02/2019" ]);
  60.        
  61.         $created->setValue( date('Y-m-d H:i') );
  62.         $expires->setValue( date('Y-m-d', strtotime("+1 days")) );
  63.         $value->setValue(123.45);
  64.         $weight->setValue(30);
  65.         $color->setValue('#FF0000');
  66.         $type->setValue('a');
  67.        
  68.         // add the fields inside the form
  69.         $this->form->addFields( [new TLabel('Id')],          [$id]);
  70.         $this->form->addFields( [new TLabel('Description')], [$description] );
  71.         $this->form->addFields( [new TLabel('Password')],    [$password] );
  72.         $this->form->addFields( [new TLabel('Created at')],  [$created],
  73.                                 [new TLabel('Expires at')],  [$expires]);
  74.         $this->form->addFields( [new TLabel('Value')],       [$value],
  75.                                 [new TLabel('Color')],       [$color]);
  76.         $this->form->addFields( [new TLabel('Weight')],      [$weight],
  77.                                 [new TLabel('Type')],        [$type]);
  78.        
  79.         $description->placeholder = 'Description placeholder';
  80.         $description->setTip('Tip for description');
  81.        
  82.         $label = new TLabel('Division', '#7D78B6', 12, 'bi');
  83.         $label->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%';
  84.         $this->form->addContent( [$label] );
  85.        
  86.         $this->form->addFields( [new TLabel('Description')], [$text] );
  87.         $text->setSize('100%', 50);
  88.        
  89.         // define the form action
  90.         $this->form->addAction('Send', new TAction(array($this, 'onSend')), 'far:check-circle green');
  91.         $this->form->addHeaderAction('Send', new TAction(array($this, 'onSend')), 'fa:rocket orange');
  92.        
  93.         // wrap the page content using vertical box
  94.         $vbox = new TVBox;
  95.         $vbox->style = 'width: 100%';
  96.         $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  97.         $vbox->add($this->form);
  98.  
  99.         parent::add($vbox);
  100.     }
  101.    
  102.     public static function onExitExpires($param)
  103.     {
  104.         echo $param['expires'];
  105.     }
  106.    
  107.     /**
  108.      * Simulates an save button
  109.      * Show the form content
  110.      */
  111.     public function onSend($param)
  112.     {
  113.         $data = $this->form->getData();
  114.        
  115.         // put the data back to the form
  116.         $this->form->setData($data);
  117.        
  118.         // creates a string with the form element's values
  119.         $message = 'Id: '           . $data->id . '<br>';
  120.         $message.= 'Description : ' . $data->description . '<br>';
  121.         $message.= 'Password : '    . $data->password . '<br>';
  122.         $message.= 'Created: '      . $data->created . '<br>';
  123.         $message.= 'Expires: '      . $data->expires . '<br>';
  124.         $message.= 'Value : '       . $data->value . '<br>';
  125.         $message.= 'Color : '       . $data->color . '<br>';
  126.         $message.= 'Weight : '      . $data->weight . '<br>';
  127.         $message.= 'Type : '        . $data->type . '<br>';
  128.         $message.= 'Text : '        . $data->text . '<br>';
  129.        
  130.         // show the message
  131.         new TMessage('info', $message);
  132.     }
  133. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top