IC
Exibir TImage no Form
Galera, estou tentando exibir uma imagem armazenada no banco de dados, utilizando um método onChangeAction, consigo exibir a imagem utilizando um TMessage, porém, quero que ela fique em um campo no form. Segue meu código:
- <?php
- class TrocaSolicitado extends TPage
- {
- protected $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_troca_solicitado');
- $this->form->setFormTitle('Solicitado');
- $SETOR = new TEntry('SETOR');
- $SETOR->setValue(TSession::getValue('SETOR'));
- $MES_DA_ESCALA = new TEntry('MES_DA_ESCALA');
- $MES_DA_ESCALA->setValue(TSession::getValue('MES_ESCALA'));
- $NOME = new TCombo('NOME');
- $CPF = new TEntry('CPF');
- $FOTO = new TImage('FOTO');
- base64_encode($FOTO);
- $SETOR->setExitAction( new TAction( array($this, 'onExitAction') ) );
- $CPF->setExitAction( new TAction( array($this, 'onFotoAction') ) );
- $NOME->setChangeAction(new TAction([$this, 'onChangeAction']));
- // add the fields
- $this->form->addFields(['SETOR: '], [$SETOR] );
- $this->form->addFields(['MES DA ESCALA: '], [$MES_DA_ESCALA] );
- $this->form->addFields(['NOME: '], [$NOME]);
- $this->form->addFields(['CPF: '], [$CPF], ['FOTO'], [$FOTO]);
- // validations
- $NOME->addValidation('NOME: ', new TRequiredValidator);
- $NOME->setSize('40%');
- $MES_DA_ESCALA->setSize('40%');
- $SETOR->setSize('40%');
- $CPF->setSize('105%');
- $this->form->addAction('Next', new TAction(array($this, 'onConfirm')), 'far:check-circle green');
- $this->form->addAction('Back', new TAction(array($this, 'onBackForm')), 'far:check-circle red');
- $pagestep = new TPageStep;
- $pagestep->addItem('SOLICITACAO');
- $pagestep->addItem('SETOR');
- $pagestep->addItem('SOLICITADO');
- $pagestep->addItem('CONFIRMAR');
- $pagestep->select('SOLICITADO');
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- // $vbox->add(new TXMLBreadCrumb('menu.xml', 'MultiStepRegistration1View'));
- $vbox->add( $pagestep );
- $vbox->add( $this->form );
- parent::add($vbox);
- }
- public static function onExitAction($param){
- $SETOR = $param['SETOR'];
- $MES_DA_ESCALA = $param['MES_DA_ESCALA'];
- TTransaction::open('parametros_gente');
- $servidores = Escalas::select('NOME','CPF')->where('MES_DA_ESCALA', '=', $MES_DA_ESCALA)->where('SETOR', '=', $SETOR)->orderBy('NOME')
- ->load();
- $result = array();
- foreach ($servidores as $obj)
- {
- $result[$obj->CPF] = $obj->NOME;
- }
- TCombo::reload('form_troca_solicitado', 'NOME', $result);
- TTransaction::close();
- }
- public static function onChangeAction($param)
- {
- @$NOME = $param['NOME'];
- TTransaction::open('pessoal');
- $servidores = Servidores::where('CPF', '=',$NOME)->load();
- $result = new stdClass;
- foreach($servidores as $obj)
- {
- $result->CPF = $obj->CPF;
- }
- TForm::sendData('form_troca_solicitado', $result);
- TTransaction::close();
- }
- public static function onFotoAction($param)
- {
- $CPF = $param['CPF'];
- TTransaction::open('pessoal');
- $fotos = ServidorFoto::where('SEQ_SERVIDOR','in',"(SELECT SEQ_SERVIDOR FROM SERVIDORES WHERE CPF = '$CPF' AND SERVIDORES.SEQ_SITUACAO = 46)")->load();
- $resultfotos = new stdClass;
- foreach($fotos as $objfotos)
- {
- $resultfotos->FOTO = new TMessage('info', '<img src="data:image/png;base64,' . base64_encode($objfotos->FOTO) . '" />' );
- //TScript::create(($objfotos->FOTO));
- }
- TForm::sendData('form_troca_solicitado', $resultfotos);
- TTransaction::close();
- }
- public function onBackForm()
- {
- // Load another page
- AdiantiCoreApplication::loadPage('SetorTroca');
- }
- /**
- * confirmation screen
- */
- public function onConfirm()
- {
- try
- {
- $this->form->validate();
- $data = $this->form->getData();
- TSession::setValue('registration_data', (array) $data);
- TSession::setValue('NOMESOLICITADO', $data->NOME);
- TSession::setValue('SETORSOLICITADO', $data->SETOR);
- AdiantiCoreApplication::loadPage('Confirmacao');
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- }
- ?>
Acho que usar javascript é mais fácil nesse caso, pois o TImage não é um input e com isso não é possível enviar informações via sendData/setData:
Nataniel, deu muito certo! Muito obrigado, brother! Agora só resta enquadra as imagens pra ficar certinho no form. Vlw mesmo!