Campos multi values não é adicionado no form Seguinte, estou tentando utilizar campos (multi values) porem não carregar no formulário. se alguém puder me ajudar agradeço. Segue código abaixo ...
RB
Campos multi values não é adicionado no form  
Seguinte, estou tentando utilizar campos (multi values) porem não carregar no formulário.

se alguém puder me ajudar agradeço.

Segue código abaixo

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


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


NR

www.adianti.com.br/forum/pt/view_3397?multi-value-nao-e-salvo-os-ite
RB

Então Nataniel,

Em primeiro lugar obrigado pela ajuda.

Fiz conforme indicou acima, porém só esta inserindo uma linha, e não estou identificando onde estou errando.

Segue trecho abaixo :

 
  1. <?php
  2. if(!empty($param['telefone']) And is_array($param['operadora_id']))
  3. {
  4. foreach($param['telefone'] as $row =>$contatos)
  5. {
  6. if($contatos)
  7. {
  8. //Adiciona contato
  9. $contato = new Contato;
  10. $contato->pessoa_id = $pessoa_id;
  11. $contato->ddi = $param['ddi'][$row];
  12. $contato->ddd = $param['dd'][$row];
  13. $contato->telefone = $param['telefone'][$row];
  14. $contato->operadora_id = $param['operadora_id'][$row];
  15. $contato->tipo_telefone_id = $param['tipo_telefone_id'][$row];
  16. $contato->email = $data->email;
  17. $contato->site = $data->site;
  18. $contato->store();
  19. //$contato_id = $contato->id;
  20. }
  21. }
  22. ?>


Aproveitando o gancho ao salvar os dados multvalues não permanecem na tela, e também quando clico em buscar cep os dados são removidos.
NR

Para esse tipo de formulário multivalue você precisa definir a função onSave como static. Mesma coisa para a função onCep.