Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Apresentar um vídeo do Youtube no iframe com url gravada em DB Boa tarde! Estou fazendo um sistema simples de EAD, a ideia basicamente e cadastrar o vídeo do youtube no formulário, e depois o outro formulário apresentar aquele vídeo, eu coloquei um botão assistir vídeo no formulário (a imagem está em anexo), e esse botão deve pegar o item gravado no campo e reproduzir no iframe. Eu não consegui fazer o botão executar essa função. Mas coloquei um ...
RF
Apresentar um vídeo do Youtube no iframe com url gravada em DB  
Boa tarde! Estou fazendo um sistema simples de EAD, a ideia basicamente e cadastrar o vídeo do youtube no formulário, e depois o outro formulário apresentar aquele vídeo, eu coloquei um botão assistir vídeo no formulário (a imagem está em anexo), e esse botão deve pegar o item gravado no campo e reproduzir no iframe. Eu não consegui fazer o botão executar essa função. Mas coloquei um valor fixo na url do iframe.

segue o código do formulário:
  1. <?php
  2. class sala_aula extends TPage
  3. {
  4.     protected $form;
  5.     private $formFields = [];
  6.     private static $database 'ead';
  7.     private static $activeRecord 'Aula';
  8.     private static $primaryKey 'id';
  9.     private static $formName 'form_sala_aula';
  10.     /**
  11.      * Form constructor
  12.      * @param $param Request
  13.      */
  14.     public function __construct$param )
  15.     {
  16.         parent::__construct();
  17.         if(!empty($param['target_container']))
  18.         {
  19.             $this->adianti_target_container $param['target_container'];
  20.         }
  21.         // creates the form
  22.         $this->form = new BootstrapFormBuilder(self::$formName);
  23.         // define the form title
  24.         $this->form->setFormTitle("Aula");
  25.         $curso = new TDBCombo('curso''ead''Curso''id''{nome}','id asc'  );
  26.         $secao = new TDBCombo('secao''ead''Secao''id''{nome}','id asc'  );
  27.         $nome = new TEntry('nome');
  28.         $id = new THidden('id');
  29.         $descricao = new TEntry('descricao');
  30.         $button_assistir_ao_video = new TButton('button_assistir_ao_video');
  31.         $url_video = new TEntry('url_video');
  32.         $video = new TElement('iframe');
  33.         $aulaconcluida = new TDBCheckGroup('aulaconcluida''ead''ItConcluida''id''{descricao}','id asc'  );
  34.         $avaliacao_aula = new TDBCheckGroup('avaliacao_aula''ead''ItAvaliacao''id''{descricao}','id asc'  );
  35.         $url_video->setExitAction(new TAction([$this,'onExibirVideo']));
  36.         $curso->addValidation("Curso", new TRequiredValidator()); 
  37.         $secao->addValidation("Seção", new TRequiredValidator()); 
  38.         $button_assistir_ao_video->setAction(new TAction([$this'onVideo']), "Assistir ao Vídeo");
  39.         $button_assistir_ao_video->addStyleClass('btn-warning');
  40.         $button_assistir_ao_video->setImage('fas:video #478FCA');
  41.         $nome->setMaxLength(100);
  42.         $descricao->setMaxLength(100);
  43.         $aulaconcluida->setLayout('horizontal');
  44.         $avaliacao_aula->setLayout('horizontal');
  45.         $nome->setEditable(false);
  46.         $curso->setEditable(false);
  47.         $secao->setEditable(false);
  48.         $url_video->setEditable(false);
  49.         $video->width '100%';
  50.         $video->height '350px';
  51.         $video->src "https://www.youtube.com/embed/T2CvkoVirkQ";
  52.         $id->setSize(200);
  53.         $nome->setSize('100%');
  54.         $curso->setSize('100%');
  55.         $secao->setSize('100%');
  56.         $descricao->setSize('100%');
  57.         $url_video->setSize('100%');
  58.         $aulaconcluida->setSize(80);
  59.         $avaliacao_aula->setSize(80);
  60.         $this->video $video;
  61.         $row1 $this->form->addFields([$curso],[$secao],[$nome]);
  62.         $row1->layout = [' col-sm-4',' col-sm-4',' col-sm-4'];
  63.         $row2 $this->form->addContent([new TFormSeparator(""'#333''18''#eee')]);
  64.         $row3 $this->form->addFields([new TLabel("Descrição:"null'14px'null)],[$id,$descricao]);
  65.         $row4 $this->form->addContent([new TFormSeparator(""'#333''18''#eee')]);
  66.         $row5 $this->form->addFields([$button_assistir_ao_video],[$url_video]);
  67.         $row5->layout = [' col-sm-2',' col-sm-10'];
  68.         $row6 $this->form->addContent([new TFormSeparator(""'#333''18''#eee')]);
  69.         $row7 $this->form->addFields([$video]);
  70.         $row7->layout = [' col-sm-12'];
  71.         $row8 $this->form->addContent([new TFormSeparator(""'#333''18''#eee')]);
  72.         $row9 $this->form->addFields([new TLabel("Aula concluída?"null'14px'null)],[$aulaconcluida],[new TLabel("Avalie:"null'14px'null)],[$avaliacao_aula]);
  73.         // create the form actions
  74.         $btn_onsave $this->form->addAction("Salvar", new TAction([$this'onSave']), 'fas:save #ffffff');
  75.         $this->btn_onsave $btn_onsave;
  76.         $btn_onsave->addStyleClass('btn-primary'); 
  77.         // vertical box container
  78.         $container = new TVBox;
  79.         $container->style 'width: 100%';
  80.         $container->class 'form-container';
  81.         if(empty($param['target_container']))
  82.         {
  83.             $container->add(TBreadCrumb::create(["Cadastro","Sala de Aula"]));
  84.         }
  85.         $container->add($this->form);
  86.         parent::add($container);
  87.     }
  88.     public static function onExibirVideo($param null
  89.     {
  90.         try 
  91.         {
  92.         $data $this->form->getData();
  93.         // Pega a informação do campo Status
  94.         $url $data->url_video;
  95.          TScript::create("
  96.               $(video).attr('src','{$url}');
  97.          ");
  98.         }
  99.         catch (Exception $e
  100.         {
  101.             new TMessage('error'$e->getMessage());    
  102.         }
  103.     }
  104.     public static function onVideo($param null
  105.     {
  106.         try 
  107.         {
  108. $url 'https://www.youtube.com/embed/k_Kv7hq77hc';
  109.         }
  110.         catch (Exception $e
  111.         {
  112.             new TMessage('error'$e->getMessage());    
  113.         }
  114.     }
  115.     public function onSave($param null
  116.     {
  117.         try
  118.         {
  119.             TTransaction::open(self::$database); // open a transaction
  120.             $messageAction null;
  121.             $this->form->validate(); // validate form data
  122.             $object = new Aula(); // create an empty object 
  123.             $data $this->form->getData(); // get form data as array
  124.             $object->fromArray( (array) $data); // load the object with data
  125.             $object->store(); // save the object 
  126.             $repository AulaConcluida::where('aula_id''='$object->id);
  127.             $repository->delete(); 
  128.             if ($data->aulaconcluida
  129.             {
  130.                 foreach ($data->aulaconcluida as $aulaconcluida_value
  131.                 {
  132.                     $aula_concluida = new AulaConcluida;
  133.                     $aula_concluida->it_concluida_id $aulaconcluida_value;
  134.                     $aula_concluida->aula_id $object->id;
  135.                     $aula_concluida->store();
  136.                 }
  137.             }
  138.             $repository AvaliacaoAula::where('aula_id''='$object->id);
  139.             $repository->delete(); 
  140.             if ($data->avaliacao_aula
  141.             {
  142.                 foreach ($data->avaliacao_aula as $avaliacao_aula_value
  143.                 {
  144.                     $avaliacao_aula = new AvaliacaoAula;
  145.                     $avaliacao_aula->it_avaliacao_id $avaliacao_aula_value;
  146.                     $avaliacao_aula->aula_id $object->id;
  147.                     $avaliacao_aula->store();
  148.                 }
  149.             }
  150.             // get the generated {PRIMARY_KEY}
  151.             $data->id $object->id
  152.             $this->form->setData($data); // fill form data
  153.             TTransaction::close(); // close the transaction
  154.             new TMessage('info'"Registro salvo"$messageAction); 
  155.         }
  156.         catch (Exception $e// in case of exception
  157.         {
  158.             //</catchAutoCode> 
  159.             new TMessage('error'$e->getMessage()); // shows the exception error message
  160.             $this->form->setData$this->form->getData() ); // keep form data
  161.             TTransaction::rollback(); // undo all pending operations
  162.         }
  163.     }
  164.     public function onEdit$param )
  165.     {
  166.         try
  167.         {
  168.             if (isset($param['key']))
  169.             {
  170.                 $key $param['key'];  // get the parameter $key
  171.                 TTransaction::open(self::$database); // open a transaction
  172.                 $object = new Aula($key); // instantiates the Active Record 
  173.                 $object->aulaconcluida AulaConcluida::where('aula_id''='$object->id)->getIndexedArray('it_concluida_id''it_concluida_id');
  174.                 $object->avaliacao_aula AvaliacaoAula::where('aula_id''='$object->id)->getIndexedArray('it_avaliacao_id''it_avaliacao_id');
  175.                 $this->form->setData($object); // fill the form 
  176.                 TTransaction::close(); // close the transaction 
  177.             }
  178.             else
  179.             {
  180.                 $this->form->clear();
  181.             }
  182.         }
  183.         catch (Exception $e// in case of exception
  184.         {
  185.             new TMessage('error'$e->getMessage()); // shows the exception error message
  186.             TTransaction::rollback(); // undo all pending operations
  187.         }
  188.     }
  189.     /**
  190.      * Clear form data
  191.      * @param $param Request
  192.      */
  193.     public function onClear$param )
  194.     {
  195.         $this->form->clear(true);
  196.     }
  197.     public function onShow($param null)
  198.     {
  199.     } 
  200. }

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (2)


NR

Você está quase lá, acho que faltou definir um id para o iframe e referenciar esse id:
  1. <?php
  2. // construct
  3. $video->id 'video';
  4. // onVideo
  5. $url $param['url_video'];
  6. TScript::create("
  7.     $('#video').attr('src','{$url}');
  8. ");
  9. ?>
RF

Boa tarde!
Nataniel, você é bom mesmo cara! Quando crescer quero ser igual você, rssss
Funcionou depois coloco aqui o código inteiro, pra servir de referência depois para os demais, deixa eu arredondar o formulário um pouco mais.
Obrigado!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!