Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Pegar o valor do campo Produto Boa tarde... Tenho um formulário e quero pegar o valor de um campo para ser usado em em uma função. No caso eu quero pegar o valor do campo produto e alimentar a variável $emp, TTransaction::open('sample'); $emp = 'ESTAÇÕES MOOCA'; ////////////////////////////////////////////// $apartir= 0; // Contagem do total de registros filt...
RF
Pegar o valor do campo Produto  
Boa tarde...

Tenho um formulário e quero pegar o valor de um campo para ser usado em em uma função.
No caso eu quero pegar o valor do campo produto e alimentar a variável $emp,

TTransaction::open('sample');
$emp = 'ESTAÇÕES MOOCA'; //////////////////////////////////////////////
$apartir= 0;

// Contagem do total de registros filtrados
$repos = new TRepository('Cliente');
$total = $repos->count();
$crit = new TCriteria();
$crit->add(new TFilter('empreendimento','=',$emp));
$autorizados = $repos->count($crit);

$criteria = new TCriteria;
$criteria->setProperty('limit' ,15);
$criteria->setProperty('offset',$apartir);
$criteria->setProperty('order','id');

$repository = new TRepository('Cliente');
$clientes = $repository -> where('empreendimento','=',$emp)
-> load();

Segue o código completo

  1. <?php
  2. /**
  3.  * EmpreendimentoForm Form
  4.  * @author  <your name here>
  5.  */
  6. class EmpreendimentoForm extends TPage
  7. {
  8.     protected $form// form
  9.     
  10.     /**
  11.     SystemSupportForm como base para envio do email
  12.      * Form constructor
  13.      * @param $param Request
  14.      */
  15.     public function __construct$param )
  16.     {
  17.         parent::__construct();
  18.         
  19.         // creates the form
  20.         $this->form = new TQuickForm('form_Empreendimento');
  21.         $this->form->class 'tform'// change CSS class
  22.         
  23.         $this->form->style 'display: table;width:100%'// change style
  24.         
  25.         $table_destino  = new TTable;
  26.         // define the form title
  27.         $this->form->setFormTitle('Peça para envio');
  28.         
  29.         // create the form fields
  30.         $id             = new TEntry('id');
  31.         $empreendimento = new TSeekButton('empreendimento');
  32.         $emailmarketing = new THtmlEditor('emailmarketing');
  33.         $unidis         = new TEntry('unidis');
  34.         $vlmenor        = new TEntry('vlmenor');
  35.         $vlmaior        = new TEntry('vlmaior');
  36.         $disparo        = new TCombo('disparo');
  37.         $proxdisparo    = new TEntry('proxdisparo'); 
  38.         $email          = new TSeekButton('email');
  39.         
  40.         // Tamanho dos campos 
  41.         $emailmarketing ->setSize('width 500');
  42.         
  43.         //Itens do estagio
  44.         $itemDisparo= array();
  45.         $itemDisparo['1']            = 'TODOS OS E-MAILS'
  46.         $itemDisparo['2']            = 'SÓ E-MAILS DO PRODUTO';
  47.         $disparo->setValue('1');
  48.         $disparo->addItems($itemDisparo);
  49.      
  50.         // Campos no formulário colocando o tamanho no final
  51.         $this->form->addQuickFields(new TLabel ('Código')  ,array ($id,       new TLabel('Produto' ) ,$empreendimento));
  52.         $this->form->addQuickFields(new TLabel ('Valor'),array ($vlmenor,  new TLabel('Maior Valor') ,$vlmaior));        
  53.         //$this->form->addQuickFields(new TLabel ('E-mail')  ,array ($email));//,  200 );
  54.         $this->form->addQuickFields(new TLabel ('E-mail')  ,array ($email,    new TLabel('')     ));//,  200 );
  55.         //Campo para digitar a peça
  56.         $this->form->addQuickFields(new TLabel ('')    ,array ($emailmarketing));//,  200 );
  57.         $this->form->addQuickFields(new TLabel ('')    ,array (new TLabel('Próximo envio as:' ) ,$proxdisparo));
  58.         $this->form->addQuickFields(new TLabel ('')    ,array ());
  59.         
  60.         //$this->form->addQuickField('Código'  , $id,  200 );
  61.         //$this->form->addQuickFields(new TLabel ('Código'),array ($id), TLabel ('Produto'),$empreendimento );
  62.         // $this->form->addQuickField('Produto' , $empreendimento,  200 );
  63.         //$this->form->addQuickField('Vl Menor', $vlmenor,  200 );
  64.         //$this->form->addQuickField('Vl Maior', $vlmaior,  200 );
  65.         
  66.         
  67.         // Campos obrigatórios          
  68.         $empreendimento        ->addValidation('Produto'  , new TRequiredValidator); 
  69.         $emailmarketing        ->addValidation('Peça'     , new TRequiredValidator);
  70.         
  71.         // Mascara para os valores
  72.         $vlmaior->setNumericMask(2,',''.'true);
  73.         $vlmenor->setNumericMask(2,',''.'true);
  74.           
  75.         if (!empty($id))
  76.         {
  77.             $id->setEditable(FALSE);
  78.         }
  79.         
  80.         // Desabilita campos
  81.         $proxdisparo  ->setEditable(FALSE);
  82.         //$vlmaior    ->setEditable(FALSE);
  83.         //$vlmenor    ->setEditable(FALSE);
  84.         
  85.         
  86.         // Chama a tela de busca
  87.         $obj2 = new LocalizaProduto//
  88.         $empreendimento->setAction(new TAction(array($obj2'onReload')));
  89.         
  90.         $locacli = new LocalizaCliente//
  91.         $email->setAction(new TAction(array($locacli'onReload')));
  92.         
  93.                 
  94.         // create the form actions
  95.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  96.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onClear')),'bs:plus-sign green');
  97.         $this->form->addQuickAction(('Envio'),  new TAction(array($this'onEnvio')),'fa:cloud-upload fa-fw');
  98.         $this->form->addQuickAction(('Envio em lote'),  new TAction(array($this'onLote')),'fa:cloud-upload fa-fw');
  99.         
  100.                 
  101.         // Sub Menu Bonito
  102.         $container = new TVBox;
  103.         $container->style 'width: 100%';
  104.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  105.         $container->add($this->form);
  106.         parent::add($container);
  107.     }
  108.     /**
  109.      * Save form data
  110.      * @param $param Request
  111.      */
  112.     public function onEnvio()
  113.     {
  114.        try
  115.         {
  116.              // get the form data
  117.             $data $this->form->getData();
  118.             // validate data
  119.             $this->form->validate();
  120.             
  121.             // open a transaction with database
  122.             TTransaction::open('permission');
  123.             
  124.             $preferences SystemPreference::getAllPreferences();
  125.             
  126.             $mail = new TMail;
  127.             $mail->setFromtrim($preferences['mail_from']) , TSession::getValue('username'));
  128.             $mail->addAddress ($data->email); //( trim($preferences['mail_support']) );
  129.             $mail->setSubject$data->empreendimento );
  130.             
  131.             if ($preferences['smtp_auth'])
  132.             {
  133.                 $mail->SetUseSmtp();
  134.                 $mail->SetSmtpHost($preferences['smtp_host'], $preferences['smtp_port']);
  135.                 $mail->SetSmtpUser($preferences['smtp_user'], $preferences['smtp_pass']);
  136.             }
  137.                 $mail->setHtmlBody ($data->emailmarketing);
  138.              // $mail->setTextBody($data->emailmarketing);
  139.             
  140.             $mail->send();
  141.             
  142.             // close the transaction
  143.             TTransaction::close();
  144.             
  145.             // Mensagem de sucesso COMENTE ELA PARA O ENVIO EM LOTE
  146.             new TMessage('info'_t('Message sent successfully'));
  147.         }
  148.         catch (Exception $e// in case of exception
  149.         {
  150.             // get the form data
  151.             $object $this->form->getData();
  152.             
  153.             // fill the form with the active record data
  154.             $this->form->setData($object);
  155.             
  156.             // shows the exception error message
  157.             new TMessage('error'$e->getMessage());
  158.             
  159.             // undo all pending operations
  160.             TTransaction::rollback();
  161.         }    
  162.     }
  163.     
  164.     /*
  165.     Envio de e-mail em lote para clientes    
  166.     */
  167.    
  168.     public function onLote ($param)
  169.     {
  170.     try
  171.         {
  172.                        
  173.             TTransaction::open('sample');
  174.             $emp 'ESTAÇÕES MOOCA';
  175.             $apartir0;
  176.                         
  177.             // Contagem do total de registros filtrados
  178.             $repos = new TRepository('Cliente');
  179.             $total $repos->count();
  180.             $crit = new TCriteria();
  181.             $crit->add(new TFilter('empreendimento','=',$emp));
  182.             $autorizados $repos->count($crit);            
  183.                        
  184.             $criteria = new TCriteria;
  185.             $criteria->setProperty('limit' ,15);
  186.             $criteria->setProperty('offset',$apartir);
  187.             $criteria->setProperty('order','id');
  188.                         
  189.             $repository = new TRepository('Cliente');
  190.             $clientes   $repository -> where('empreendimento','=',$emp)
  191.                                       -> load();
  192.             
  193.             foreach ($clientes as $cliente)
  194.             {  
  195.                // começo do código de envio 
  196.                try
  197.                 {
  198.                      // get the form data
  199.                     $data $this->form->getData();
  200.                     // validate data
  201.                     $this->form->validate();
  202.                     
  203.                     // open a transaction with database
  204.                     TTransaction::open('permission');
  205.                     
  206.                     $preferences SystemPreference::getAllPreferences();
  207.                     
  208.                     $mail = new TMail;
  209.                     $mail->setFromtrim($preferences['mail_from']) , TSession::getValue('username'));
  210.                     $data->email $cliente->email;
  211.                     $mail->addAddress ($data->email); //( trim($preferences['mail_support']) );
  212.                     $mail->setSubject$data->empreendimento );
  213.                     
  214.                     if ($preferences['smtp_auth'])
  215.                     {
  216.                         $mail->SetUseSmtp();
  217.                         $mail->SetSmtpHost($preferences['smtp_host'], $preferences['smtp_port']);
  218.                         $mail->SetSmtpUser($preferences['smtp_user'], $preferences['smtp_pass']);
  219.                     }
  220.                         $mail->setHtmlBody ($data->emailmarketing);
  221.                      // $mail->setTextBody($data->emailmarketing);
  222.                     
  223.                     $mail->send();
  224.                     
  225.                     // close the transaction
  226.                     TTransaction::close();
  227.                     
  228.                     // Mensagem de sucesso COMENTE ELA PARA O ENVIO EM LOTE
  229.                     //new TMessage('info', _t('Message sent successfully'));
  230.                 }
  231.                 catch (Exception $e// in case of exception
  232.                 {
  233.                     // get the form data
  234.                     $object $this->form->getData();
  235.                     
  236.                     // fill the form with the active record data
  237.                     $this->form->setData($object);
  238.                     
  239.                     // shows the exception error message
  240.                     new TMessage('error'$e->getMessage());
  241.                     
  242.                     // undo all pending operations
  243.                     TTransaction::rollback();
  244.                 }  
  245.                 // Aviso de envio dos emails termonado   
  246.                 //new TMessage ('info',('E-mail Marqueting Enviado')); 
  247.             }// Fim do código de envio FIM DO FOREACH    
  248.                 
  249.             
  250.             TTransaction::close();       
  251.         }//-------------------------------------
  252.       catch (Exception $e)
  253.         {
  254.           new TMessage('error',$e->getMessage());        
  255.         }
  256.       // SALVA NO BANCO DE DADOS O ÚLTIMO ENVIO EM LOTE  
  257.         try
  258.         {   //***********************************************
  259.             $prxenvio    date ('i');
  260.             if ($prxenvio == 44) {
  261.                 $j date('H');
  262.                 $j += 1;
  263.                 $proxdisparo $j ':00';
  264.             }else{
  265.                 $prxenvio    += 15;
  266.                 $proxdisparo = (date ('H')).':'.$prxenvio;
  267.             }
  268.             $obj         = new StdClass;
  269.             $obj         ->proxdisparo   $proxdisparo ;
  270.             TForm::sendData('form_Empreendimento'$obj);  
  271.             //***********************************************
  272.             TTransaction::open('sample'); // open a transaction
  273.             $this->form->validate(); // validate form data
  274.             $object = new Empreendimento;  // create an empty object
  275.             $data $this->form->getData(); // get form data as array
  276.             $object->fromArray( (array) $data); // load the object with data
  277.             $object->proxdisparo $obj;
  278.             $object->store(); // save the object
  279.             
  280.             // get the generated id
  281.             $data->id $object->id;
  282.             
  283.             $this->form->setData($data); // fill form data
  284.             TTransaction::close(); // close the transaction
  285.             
  286.             new TMessage('info', ('E-mails enviados com sucesso!'));
  287.         }
  288.         catch (Exception $e// in case of exception
  289.         {
  290.             new TMessage('error'$e->getMessage()); // shows the exception error message
  291.             $this->form->setData$this->form->getData() ); // keep form data
  292.             TTransaction::rollback(); // undo all pending operations
  293.         }
  294.     }
  295.     
  296.     /**
  297.      * Save form data
  298.      * @param $param Request
  299.      */
  300.     public function onSave$param )
  301.     {
  302.         try
  303.         {  
  304.             TTransaction::open('sample'); // open a transaction
  305.             $this->form->validate(); // validate form data
  306.             $object = new Empreendimento;  // create an empty object
  307.             $data $this->form->getData(); // get form data as array
  308.             $object->fromArray( (array) $data); // load the object with data
  309.             $object->store(); // save the object
  310.             
  311.             // get the generated id
  312.             $data->id $object->id;
  313.             
  314.             $this->form->setData($data); // fill form data
  315.             TTransaction::close(); // close the transaction
  316.             
  317.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  318.         }
  319.         catch (Exception $e// in case of exception
  320.         {
  321.             new TMessage('error'$e->getMessage()); // shows the exception error message
  322.             $this->form->setData$this->form->getData() ); // keep form data
  323.             TTransaction::rollback(); // undo all pending operations
  324.         }
  325.     }
  326.     
  327.     /**
  328.      * Clear form data
  329.      * @param $param Request
  330.      */
  331.     public function onClear$param )
  332.     {
  333.         $this->form->clear(TRUE);
  334.     }
  335.     
  336.     
  337.     /**
  338.      * Load object to form data
  339.      * @param $param Request
  340.      */
  341.     public function onEdit$param )
  342.     {
  343.         try
  344.         {
  345.             if (isset($param['key']))
  346.             {
  347.                 $key $param['key'];  // get the parameter $key
  348.                 TTransaction::open('sample'); // open a transaction
  349.                 $object = new Empreendimento($key); // instantiates the Active Record
  350.                 $this->form->setData($object); // fill the form
  351.                 TTransaction::close(); // close the transaction
  352.             }
  353.             else
  354.             {
  355.                 $this->form->clear(TRUE);
  356.             }
  357.         }
  358.         catch (Exception $e// in case of exception
  359.         {
  360.             new TMessage('error'$e->getMessage()); // shows the exception error message
  361.             TTransaction::rollback(); // undo all pending operations
  362.         }
  363.     }
  364. }

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (1)


NR

Você deve fazer a mesma coisa que é feita na função onEnvio, buscar as informações do formulário através do método getData:
  1. <?php
  2. $data $this->form->getData();
  3. ?>