Hi all ,
I have first time created a form with allowing multiple selections on a field.
The html output looks like it should with a hidden field and several checkboxes.
The controller function is baked standard for add an edit. But I receive no data in the datebase.
Hier are the functions:
add.ctp
<?php $array = $this->ViewTools->getallparameter('P', $product); ?> <?= $this->Element('cssTop', array('large' => 12, 'medium' => 9, 'product' => $product, 'name' => $array)); ?><?= $this->Form->create($user) ?>
<fieldset>
<legend><?= __('Erstellen') ?></legend>
<ul class="tab">
<li><a href="javascript:void(0)" class="tablinks" onclick="openTab(event, 'London')" id="defaultOpen">Name</a></li>
<li><a href="javascript:void(0)" class="tablinks" onclick="openTab(event, 'Paris')">Adresse</a></li>
<li><a href="javascript:void(0)" class="tablinks" onclick="openTab(event, 'Tokyo')">Wohnung</a></li>
</ul>
<div id="London" class="tabcontent">
<?php
echo $this->Form->input('last_name',['id' => 'last']);
echo $this->Form->input('first_name',['id' => 'first']);
echo $this->Form->input('username',['id' => 'total']);
echo $this->Form->input('birthday', array(
'label' => 'Geburtstag',
'dateFormat' => 'DMY',
'minYear' => date('Y') - 80,
'maxYear' => date('Y') - 2 ));
$options = [
'1' => 'ledig',
'2' => 'verheiratet',
'3' => 'verwitwet',
];
echo $this->Form->select('civil_status', $options);
echo $this->Form->input('password');
echo $this->Form->input('userfunction_id', ['options' => $userfunctions]); ?>
</div>
<div id="Paris" class="tabcontent">
<?php
echo $this->Form->input('company');
echo $this->Form->input('street', ['default' => 'Schillerstraße']);
echo $this->Form->input('no');
echo $this->Form->input('city', ['default' => 'Ginsheim-Gustavsburg']);
echo $this->Form->input('zip', ['default' => '65462']);
echo $this->Form->input('phone');
echo $this->Form->input('mobile');
echo $this->Form->input('fax');
echo $this->Form->input('email');
echo $this->Form->input('iban');
echo $this->Form->input('bic'); ?>
</div>
<div id="Tokyo" class="tabcontent">
<?php
$options = [
'0' => 'kein Status',
'1' => 'aktiv',
'2' => 'passiv',
'3' => 'ausgetreten',
];
echo $this->Form->radio('status', $options);
echo $this->Form->label('User.member', 'Mitglied');
$options = [
'1' => 'Mitglied',
'2' => 'Interessent',
'3' => 'Ehemaliger',
'4' => 'Bewohner',
'5' => 'Partner',
'6' => 'Warteliste',
'7' => 'Gärtner',
];
//echo $this->Form->select('member', ['options' => $mamberList , 'multiple' => true] );
echo $this->Form->select('member', $options, ['multiple' => 'checkbox']);
echo $this->Form->input('userappartment_id', ['options' => $userappartments]);
echo $this->Form->input('userparking_id', ['options' => $userparkings]);
echo $this->Form->input('contact');
?>
</div>
</fieldset>
<?= $this->Form->button(__('Speichern')) ?>
<?= $this->Form->end() ?>
<?= $this->Element('jsUsers'); ?>
UsersController:
public function add() {
$this->set('userfunc', $this->Auth->user('userfunction_id'));
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
$userfunctions = $this->Users->Userfunctions->find('list', ['limit' => 200]);
$userappartments = $this->Users->Userappartments->find('list', ['limit' => 200]);
$userparkings = $this->Users->Userparkings->find('list', ['limit' => 200]);
$this->set(compact('user', 'userfunctions', 'userappartments', 'userparkings'));
$this->set('_serialize', ['user']);
}
I am wondering, if I need to join the values with a seperator before storing in the database.
Has anyone a tip or suggestion please??
Regards Klaus