ET
Erro ao redirecionar form para um FormView depois de Salvar
Bom dia, preciso redirecionar uma página para um FormView depois de salvar o formulário. Estou utilizando o seguinte código no onSave:
E estou recebendo o erro: Método AdiantiControlTAction::__construct deve receber um parâmetro do tipo Callback
Verifique se a ação (ReciboFormView::onReload) existe
Alguém sabe como posso resolver isso?
Desde já agradeço a ajuda.
Código do Form:
E estou recebendo o erro: Método AdiantiControlTAction::__construct deve receber um parâmetro do tipo Callback
Verifique se a ação (ReciboFormView::onReload) existe
Alguém sabe como posso resolver isso?
Desde já agradeço a ajuda.
Código do Form:
- <?php
- /**
- * ReciboForm Form
- * @author <your name here>
- */
- class ReciboForm extends TPage
- {
- protected $form; // form
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Recibo');
- $this->form->setFormTitle('Recibo');
- $this->form->setClientValidation(true);
- // create the form fields
- $id = new TEntry('id');
- $recebi_de = new TEntry('recebi_de');
- $cpf_cnpj = new TEntry('cpf_cnpj');
- $valor = new TEntry('valor');
- $dt_emissao = new TDate('dt_emissao');
- $referente_a = new TEntry('referente_a');
- // add the fields
- $this->form->addFields( [ new TLabel('Código') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Recebi de*', '#FF0000') ], [ $recebi_de ], [ new TLabel('Cpf ou Cnpj') ], [ $cpf_cnpj ] );
- $this->form->addFields( [ new TLabel('Valor R$*', '#FF0000') ], [ $valor ], [ new TLabel('Na data') ], [ $dt_emissao ] );
- $this->form->addFields( [ new TLabel('Referente a') ], [ $referente_a ] );
- $recebi_de->addValidation('Recebi de', new TRequiredValidator);
- $valor->addValidation('Valor R$', new TRequiredValidator);
- // set sizes
- $id->setSize('100');
- $recebi_de->setSize('100%');
- $cpf_cnpj->setSize('100%');
- $valor->setSize('100%');
- $dt_emissao->setSize('100%');
- $referente_a->setSize('100%');
- $recebi_de->setMaxLength(100);
- $cpf_cnpj->setMaxLength(20);
- $referente_a->setMaxLength(100);
- $valor->setNumericMask(2, ',', '.', true);
- $dt_emissao->setDatabaseMask('yyyy-mm-dd');
- $dt_emissao->setMask('dd/mm/yyyy');
- if (!empty($id))
- {
- $id->setEditable(FALSE);
- }
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:save');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('loja'); // open a transaction
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
- $this->form->validate(); // validate form data
- $data = $this->form->getData(); // get form data as array
- $object = new Recibo; // create an empty object
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // get the generated id
- $data->id = $object->id;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- $message = 'Registro salvo';
- $action = new TAction(array('ReciboFormView', 'onReload'));
- new TMessage('info', $message, $action);
- //new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear(TRUE);
- }
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('loja'); // open a transaction
- $object = new Recibo($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear(TRUE);
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
- ?>
Falta criar o método onReload na classe ReciboForm