I'm having trouble inserting or changing data using the HABTM template, it does not recognize 3 fields, but is recognizing hidden fields normally.
It follows the files with programming, they are 3 tables, one with the data of the clients, others with the data of the chosen options ( usuario
, senha
, id_opcao
, etc) and another with which option is (Control Panel, Database, etc.)
client.php - model
public $hasAndBelongsToMany = array (
'opcoes_clientes' => array (
'className' => 'opcoes' ,
)
);
ClientsController.php
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Cliente->save($this->request->data)) {
$this->Cliente->saveAssociated($this->request->data);
$this->Session->setFlash('O cliente foi editado com sucesso!',
'alert', array( 'plugin' => 'BoostCake', 'class' => 'alert-success' ));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('O cliente não foi editado. Tente novamente.', 'alert', array(
'plugin' => 'BoostCake', 'class' => 'alert-error'
));
}
} else {
$this->request->data = $this->Cliente->read();
$this->set('clientes', $this->Cliente->read());
}
edit.ctp (summarized)
echo $this->Form->create("Cliente");
echo $this->Form->input('nome', $options);
echo $this->Form->input('email', $options);
echo $this->Form->input('telefone', $options);
echo $this->Form->input('mais', $options);
foreach($opcoes as $data):
echo $this->Form->hidden('opcoes_clientes.opco_id', array('value'=> $id));
echo $this->Form->hidden('opcoes_clientes.cliente_id', array('value'=> $clientes['Cliente']['id']));
echo $this->Form->input('opcoes_clientes.host', $options);
echo $this->Form->input('opcoes_clientes.user', $options);
echo $this->Form->input('opcoes_clientes.password', $options);
endforeach;
echo $this->Form->end($options);
All client data is changed normally, but in opcoes_cliente
it only inserts (if it does not) the opco_id
and cliente_id
. The fields host
, user
and password
are empty even if some value is filled in.