Campos labels é adicionado mais de uma vez - Multivalues Olá, Estou criando um form multivalues, porém esta gerando os labels duas vezes e também só esta salvado o ultimo campo, aguém pode me ajudar a identificar onde esta os erros. segue código abaixo ...
RB
Campos labels é adicionado mais de uma vez - Multivalues  
Olá,

Estou criando um form multivalues, porém esta gerando os labels duas vezes e também só esta salvado o ultimo campo, aguém pode me ajudar a identificar onde esta os erros.

segue código abaixo



 
  1. <?php
  2. class ClienteFisicoBuilder extends TPage
  3. {
  4. protected $form;
  5. protected $table_contato;
  6. protected $frame_contato;
  7. protected $deta_row;
  8. public function __construct($param)
  9. {
  10. parent::__construct($param);
  11. $this->form = new BootstrapFormBuilder('frm_cliente_fisico');
  12. $this->form->setFormTitle('Cliente');
  13. $this->form->style='font-family:Arial Narrow;width:100%;';
  14. $dados_cliente = new TLabel('Dados Pessoais', '#1F4E78', 12, 'b');
  15. $dados_cliente->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%;float:left;margin-top:-20px;font-family:Arial Narrow;';
  16. $this->form->addContent( [$dados_cliente] );
  17. $lbl_id = new TLabel('ID','#1F4E78');
  18. $label_nome = new TLabel('Nome','#1F4E78');
  19. $label_nome->style='text-align:left;float:left;font-family:Arial Narrow;';
  20. $lbl_data_nascto = new TLabel('Data Nascimento','#1F4E78');
  21. $lbl_data_nascto->style='text-align:left;float:left;font-family:Arial Narrow;';
  22. $lbl_estado_civil = new TLabel('Estado Cívil','#1F4E78');
  23. $lbl_estado_civil->style='text-align:left;float:left;font-family:Arial Narrow;';
  24. $cliente_id = new TEntry('cliente_id');
  25. $cliente_id->setEditable(false);
  26. $nome = new TEntry('nome');
  27. $nome->style='text-align:left;float:left;';
  28. $nome->addValidation('Nome', new TRequiredValidator);
  29. $data_nascimento = new TDate('data_nascimento');
  30. $data_nascimento->addValidation('Data Nascimento', new TRequiredValidator);
  31. $data_nascimento->style='text-align:left;float:left;';
  32. $data_nascimento->setMask('dd/mm/yyyy'); // define date mask
  33. $estado_civil = new TDBCombo('estado_civil_id','sgvo', 'Civil', 'id', 'descricao');
  34. $estado_civil->setDefaultOption(false);
  35. $lbl_genero = new TLabel('Genero','#1F4E78');
  36. $lbl_genero->style ='text-align:left;float:left;width:100%;font-family:Arial Narrow;';
  37. $genero_id = new TCombo('genero_id');
  38. $genero_id->addItems( ['1' => 'Masculino', '2' => 'Feminino'] );
  39. $genero_id->setDefaultOption(false);
  40. $lbl_cpf = new TLabel('CPF','#1F4E78');
  41. $cpf = new TEntry('cpf');
  42. $cpf->setMask('000.000.000.00');
  43. $cpf->addValidation('CPF', new TCPFValidator, new TMaxValueValidator,array(14));
  44. $lbl_cpf->style='text-align:left;float:left;font-family:Arial Narrow;';
  45. $lbl_rg = new TLabel('RG','#1F4E78');
  46. $rg = new TEntry('rg');
  47. $rg->setMask('00.000.000.00');
  48. $rg->setMaxLength(12);
  49. $lbl_rg->style='text-align:left;float:left;font-family:Arial Narrow;';
  50. /*
  51. $lbl_cnh = new TLabel('CNH','#1F4E78');
  52. $cnh = new TEntry('cnh');
  53. $cnh->setMask('00.000.000.00');
  54. $cnh->setMaxLength(12);
  55. $lbl_cnh->style='text-align:left;float:left;';
  56. */
  57. $lbl_etnia = new TLabel('Etnia','#1F4E78');
  58. $etnia_id = new TDBCombo('etnia_id','sgvo','Etnia','id','descricao');
  59. $etnia_id->setDefaultOption(false);
  60. // $this->form->addFields( [$label_id,$id] );
  61. $this->form->addFields( [$lbl_id,$label_nome,$lbl_data_nascto,$lbl_estado_civil] );
  62. $this->form->addFields( [$cliente_id,$nome,$data_nascimento,$estado_civil] );
  63. $this->form->addFields( [$lbl_genero,$lbl_etnia,$lbl_cpf,$lbl_rg] );
  64. $this->form->addFields( [$genero_id,$etnia_id,$cpf,$rg] );
  65. //dados de contato
  66. $contato = new TLabel('Contato', '#1F4E78', 12, 'b');
  67. $contato->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%;font-family:Arial Narrow;';
  68. $lbl_ddi = new TLabel('DDI','#1F4E78');
  69. $lbl_ddi->style='text-align:left;font-family:Arial Narrow;';
  70. $lbl_dd = new TLabel('DDD','#1F4E78');
  71. $lbl_dd->style='text-align:left;font-family:Arial Narrow;';
  72. $lbl_tipo_telefone = new TLabel('Tipo Telefone','#1F4E78');
  73. $lbl_tipo_telefone->style='text-align:left;font-family:Arial Narrow;';
  74. $lbl_telefone = new TLabel('Telefone','#1F4E78');
  75. $lbl_telefone->style='text-align:left;font-family:Arial Narrow;';
  76. $lbl_operadora = new TLabel('Operadora','#1F4E78');
  77. $lbl_operadora->style='text-align:left;font-family:Arial Narrow;';
  78. $lbl_email = new TLabel('Email','#1F4E78');
  79. $lbl_email->style='text-align:left;;font-family:Arial Narrow;';
  80. $email = new TEntry('email');
  81. //$email->addValidation('email', new TEmailValidator); // email field
  82. $lbl_site = new TLabel('Site','#1F4E78');
  83. $lbl_site->style='text-align:left;font-family:Arial Narrow;';
  84. $site = new TEntry('site');
  85. //Cria tabela contato adiciona campos
  86. $this->table_contato = new TTable;
  87. $this->table_contato->style='font-family:Arial Narrow;';
  88. $this->table_contato->width='100%';
  89. $this->table_contato->addSection('thead');
  90. //$row = $this->table_contato->addRow();
  91. $this->frame_contato = new TFrame;
  92. $this->frame_contato->style='border:none;float:lef; margin-left:-15px;';
  93. //$frame_contato->setLegend('Contato');
  94. $this->frame_contato->add($contato);
  95. $row = $this->table_contato->addRowSet($lbl_ddi,$lbl_dd,$lbl_tipo_telefone,$lbl_telefone,$lbl_operadora);
  96. $this->frame_contato->add($row);
  97. $this->form->addContent([$this->frame_contato]);
  98. //adiciona contato web
  99. $this->form->addFields( [$lbl_email,$lbl_site] );
  100. $this->form->addFields( [$email,$site] );
  101. //dados de correspondência
  102. $lbl_endereco = new TLabel('Endereco', '#1F4E78', 12, 'b');
  103. $lbl_endereco->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%;font-family:Arial Narrow;';
  104. $lbl_cep = new TLabel('Cep', '#1F4E78');
  105. $lbl_cep->style='text-align:left;border-bottom:1px solid #c0c0c0;font-family:Arial Narrow;';
  106. $cep = new TEntry('cep');
  107. $cep->addValidation('CEP', new TRequiredValidator, new TMaxValueValidator,array(8));
  108. $lbl_logradouro = new TLabel('Logradouro', '#1F4E78');
  109. $lbl_logradouro->style='text-align:left;border-bottom:1px solid #c0c0c0;font-family:Arial Narrow;';
  110. $logradouro = new TEntry('logradouro');
  111. $logradouro->style='float:left;';
  112. $logradouro->addValidation('Logradouro', new TRequiredValidator);
  113. $lbl_numero = new TLabel('Número', '#1F4E78');
  114. $lbl_numero->style='text-align:left;border-bottom:1px solid #c0c0c0;font-family:Arial Narrow;';
  115. $numero = new TEntry('numero');
  116. $numero->addValidation('Número', new TRequiredValidator);
  117. $lbl_bairro = new TLabel('Bairro', '#1F4E78');
  118. $lbl_bairro->style='text-align:left;border-bottom:1px solid #c0c0c0;font-family:Arial Narrow;';
  119. $bairro = new TEntry('bairro');
  120. $bairro->addValidation('Bairro', new TRequiredValidator);
  121. $lbl_cidade = new TLabel('Cidade', '#1F4E78');
  122. $lbl_cidade->style='text-align:left;border-bottom:1px solid #c0c0c0;width:100%;font-family:Arial Narrow;';
  123. $cidade = new TEntry('cidade');
  124. $cidade->addValidation('Cidade', new TRequiredValidator);
  125. $lbl_uf = new TLabel('Estado', '#1F4E78');
  126. $lbl_uf->style='text-align:left;border-bottom:1px solid #c0c0c0;font-family:Arial Narrow;';
  127. $uf = new TEntry('uf');
  128. $uf->addValidation('Estado', new TRequiredValidator);
  129. $lbl_complemento = new TLabel('Complemento', '#1F4E78');
  130. $lbl_complemento->style='text-align:left;border-bottom:1px solid #c0c0c0;font-family:Arial Narrow;';
  131. $complemento = new TEntry('complemento');
  132. $lbl_id->setSize('10%');
  133. $cliente_id->setSize('10%');
  134. $label_nome->setSize('30%');
  135. $nome->setSize('30%');
  136. $lbl_data_nascto->setSize('20%');
  137. $data_nascimento->setSize('20%');
  138. $lbl_estado_civil->setSize('20%');
  139. $estado_civil->setSize('20%');
  140. $lbl_genero->setSize('20%');
  141. $genero_id->setSize('20%');
  142. $lbl_cpf->setSize('20%');
  143. $cpf->setSize('20%');
  144. $lbl_rg->setSize('20%');
  145. $rg->setSize('20%');
  146. //$lbl_cnh->setSize('19%');
  147. //$cnh->setSize('19%');
  148. $lbl_etnia->setSize('20%');
  149. $etnia_id->setSize('20%');
  150. $lbl_ddi->setSize('40');
  151. $lbl_dd->setSize('40');
  152. $lbl_tipo_telefone->setSize('100');
  153. $lbl_telefone->setSize('100');
  154. $lbl_email->setSize('40%');
  155. $lbl_site->setSize('40%');
  156. $email->setSize('40%');
  157. $site->setSize('40%');
  158. $lbl_cep->setSize('28.5%');
  159. $cep->setSize('20%');
  160. $lbl_logradouro->setSize('40%');
  161. $logradouro->setSize('40%');
  162. $lbl_numero->setSize('11.88%');
  163. $numero->setSize('11.88%');
  164. $lbl_bairro->setSize('20%');
  165. $lbl_cidade->setSize('32%');
  166. $lbl_uf->setSize('8%');
  167. $bairro->setSize('20%');
  168. $cidade->setSize('32%');
  169. $uf->setSize('8%');
  170. $lbl_complemento->setSize('20%');
  171. $complemento->setSize('20%');
  172. $btn_cep = new TButton('btn_cep');
  173. $btn_cep->setSize(100);
  174. $btn_cep->style='float:left;padding-rigth:10px;color:#1F4E78';
  175. $btn_cep->setAction(new TAction(array($this,'onCep')),'Busca Cep');
  176. $btn_cep->setImage('fa:search blue');
  177. $this->form->addFields( [$lbl_endereco] );
  178. $this->form->addFields( [$lbl_cep,$lbl_logradouro,$lbl_numero] );
  179. $this->form->addFields( [$cep,$btn_cep,$logradouro,$numero] );
  180. $this->form->addFields( [$lbl_bairro,$lbl_cidade,$lbl_uf,$lbl_complemento] );
  181. $this->form->addFields( [$bairro,$cidade,$uf,$complemento] );
  182. $this->form->addAction('Salvar', new TAction(array($this, 'onSave')), 'ico_save.png');
  183. //wrap the page content using vertical box
  184. $vbox = new TVBox;
  185. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  186. $vbox->add($this->form);
  187. parent::add($this->form);
  188. }
  189. public static function onSave($param){
  190. $organizacao_id = TSession::getValue('organizacion_id'); // pega id da empresa
  191. $atualizacao = date('Y-m-d H:m:s');
  192. try
  193. {
  194. TTransaction::open('centinel'); // open a transaction
  195. $pessoa = new Pessoa;
  196. /*
  197. // Enable Debug logger for SQL operations inside the transaction
  198. TTransaction::setLogger(new TLoggerSTD); // standard output
  199. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  200. */
  201. $pessoa->nome = $param['nome'];
  202. $pessoa->data_nascimento = TDate::date2us($param['data_nascimento']);
  203. $pessoa->organizacao_id = $organizacao_id;
  204. $pessoa->tipo_pessoa_id = 1;
  205. $pessoa->store(); // save the object
  206. $pessoa_id = $pessoa->id;
  207. if($pessoa_id)
  208. {
  209. $cliente = new Cliente;
  210. $cliente->pessoa_id = $pessoa_id;
  211. $cliente->organizacao_id = $organizacao_id;
  212. $cliente->store();
  213. $cliente_id = $cliente->id;
  214. if($cliente_id)
  215. {
  216. $fisica = new Fisica;
  217. $fisica->pessoa_id = $pessoa_id;
  218. $fisica->cpf = str_replace(".", "", $param['cpf']);
  219. $fisica->rg = str_replace(".", "", $param['rg']);
  220. $fisica->genero_id = $param['genero_id'];
  221. $fisica->civil_id = $param['estado_civil_id'];
  222. $fisica->organizacao_id = $organizacao_id;
  223. $fisica->etnia_id = $param['etnia_id'];
  224. $fisica->store();
  225. }
  226. if(!empty($param['telefone']) And is_array($param['telefone']))
  227. {
  228. foreach($param['telefone'] as $row =>$contatos)
  229. {
  230. if($contatos)
  231. {
  232. //Adiciona contato
  233. $contato = new Contato;
  234. $contato->pessoa_id = $pessoa_id;
  235. $contato->ddi = $param['ddi'][$row];
  236. $contato->ddd = $param['dd'][$row];
  237. $contato->telefone = $param['telefone'][$row];
  238. $contato->tipo_telefone_id = $param['tipo_telefone_id'][$row];
  239. $contato->operadora_id = $param['operadora_id'][$row];
  240. $contato->store();
  241. }
  242. }
  243. }
  244. //adiciona contato web
  245. if(!empty($param['email']) or $param['site'])
  246. {
  247. $contato_web = new Contatoweb;
  248. $contato_web->pessoa_id = $pessoa_id;
  249. $contato_web->email = $param['email'];
  250. $contato_web->site = $param['site'];
  251. $contato_web->store();
  252. }
  253. }
  254. $data = new stdClass;
  255. $data->cliente_id = $pessoa->id;
  256. TForm::sendData('frm_cliente_fisico', $data);
  257. TTransaction::close();// close the transaction
  258. // reload form and session items
  259. // $this->onEdit(array('key'=>$pessoa->id));
  260. }
  261. catch (Exception $e) // in case of exception
  262. {
  263. new TMessage('error', $e->getMessage());
  264. TForm::sendData('frm_cliente_fisico', $data);// keep form data
  265. TTransaction::rollback();
  266. }
  267. }
  268. //method onCep()
  269. public static function onCep($param){
  270. $retorno = Endereco::BuscaCep($param['cep']);
  271. if ( $retorno )
  272. {
  273. $obj = new StdClass;
  274. $obj->ibge = strtoupper( $retorno['ibge']);
  275. $obj->gia = strtoupper( $retorno['gia']);
  276. $obj->logradouro = strtoupper( $retorno['logradouro']);
  277. $obj->bairro = strtoupper( $retorno['bairro']);
  278. $obj->cidade = strtoupper( $retorno['localidade']);
  279. $obj->uf = strtoupper( $retorno['uf']);
  280. TForm::sendData('frm_cliente_fisico', $obj);
  281. TScript::create('$("input[name=numero]").focus();');
  282. }
  283. else {
  284. new TMessage("error", "CEP - Em Branco ou Inválido");
  285. }
  286. }
  287. public function onEdit($param)
  288. {
  289. }
  290. public function addDetailRow($param)
  291. {
  292. $uniqid = mt_rand(1000000, 9999999);
  293. $ddi = new TEntry('ddi[]');
  294. $ddi->setValue('55');
  295. $ddi->addValidation('DDI', new TMaxValueValidator,array(2));
  296. $ddi->setId('ddi_'.$uniqid);
  297. $dd = new TEntry('dd[]');
  298. $dd->setValue('011');
  299. $dd->addValidation('DDD', new TMaxValueValidator,array(2));
  300. $dd->setId('dd_'.$uniqid);
  301. $tipo_telefone_id = new TDBCombo('tipo_telefone_id[]','centinel','TipoTelefone','id','descricao');
  302. $tipo_telefone_id->setDefaultOption(false);
  303. $tipo_telefone_id->setId('tipo_telefone_id_'.$uniqid);
  304. $telefone = new TEntry('telefone[]');
  305. $telefone->setMask('9999-9999');
  306. $telefone->setId('telefone_'.$uniqid);
  307. $operadora_id = new TDBCombo('operadora_id[]','centinel','Operadora','id','nome');
  308. $operadora_id->setDefaultOption(false);
  309. $operadora_id->setId('operadora_id_'.$uniqid);
  310. // create delete button
  311. $del = new TImage('fa:trash-o red');
  312. $del->onclick = 'ttable_remove_row(this)';
  313. $frame = $this->frame_contato;
  314. $row = $this->table_contato;
  315. $row->addRowSet($ddi,$dd,$tipo_telefone_id,$telefone,$operadora_id,$del);
  316. $frame->add($row);
  317. $this->detail_row ++;
  318. $ddi->setSize('40');
  319. $dd->setSize('40');
  320. $tipo_telefone_id->setSize('100');
  321. $telefone->setSize('100');
  322. $operadora_id ->setSize('100');
  323. }
  324. public function onClear($param)
  325. {
  326. $this->table_contato->addSection('tbody');
  327. $this->addDetailRow(new stdClass);
  328. //criar e adicionar botão
  329. $add = new TButton('clone');
  330. $add->setLabel('Add');
  331. $add->setImage('fa:plus-circle green');
  332. $add->addFunction('ttable_clone_previous_row(this)');
  333. //adiciona botão a tabela
  334. $this->table_contato->addRowSet($add);
  335. //$this->frame_contato->add($add_contato);
  336. }
  337. }
  338. ?>


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 (2)


HT

Precisando também de ajuda com esse componente, sendo que meu problema é que quando recebo o array, os valores vem separados por :(Dois pontos).
NR

Está duplicando os labels pela forma como a tabela está sendo adicionada. No construtor você adiciona uma linha no frame, e depois na função addDetailRow você adiciona a tabela para cada registro. Adicione a tabela ao frame somente uma vez, no construtor, e depois adicione as linhas à tabela:
 
  1. <?php
  2. // construct
  3. $this->frame_contato->add($this->table_contato);
  4. //addDetailRow
  5. $row->addRowSet($ddi,$dd,$tipo_telefone_id,$telefone,$operadora_id,$del);
  6. //$frame->add($row); nao precisa adicionar a linha ao frame, pois a tabela ja foi adicionada
  7. ?>