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

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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. ?>