I want to create two Input Fields. One will save an Int the other one a value like K-0001. After saving those Input Fields and reloading the Form, I want to see inside the Fields the last Values they saved to the Database.
The reason I want to do it like this, is because that way I only need to change the last digit and can save the Form again. The Problem is I don't know how I can do that.
Example for better Explaining:
Form:
Field 1: First Value 20000. I Input the number 20001.
Field 2: First Value K-0000. I Input the text K-0001.
After saving my Form and Reloading it I want that it looks like this.
Field 1: Shows the Value 20001. I change it to 20005.
Field 2: Shows the Value K-0001. I change it to K-0005.
And again:
Field 1: Shows the Value 20005. I change it to 20007.
Field 2: Shows the Value K-0005. I change it to K-0007.
etc.
I guess that I need to create a Function which gets the Values from my Database. After that I need to put those inside my Input Fields, atleast that's what I'm thinking.
Code:
add.ctp
div class="customers form large-9 medium-8 columns content">
<?= $this->Form->create($customer) ?>
<fieldset>
<legend><?= __('Neuen Kunden erstellen') ?></legend>
<?php
echo $this->Form->control('tour_id', ['options' => $tours, 'empty' => true]);
/* echo $this->Form->control('order', array('label' => __('Bestellung', true))); */
echo $this->Form->control('kdnr', array('label' => __('Kundennummer', true)));
echo $this->Form->control('debinr', array('label' => __('Debitorennummer', true)));
echo $this->Form->control('anrede', array('label' => __('Anrede', true)));
echo $this->Form->control('name', array('label' => __('Name', true)));
echo $this->Form->control('strasse', array('label' => __('Straße', true)));
echo $this->Form->control('plz', array('label' => __('PLZ', true)));
echo $this->Form->control('ort', array('label' => __('Ort', true)));
echo $this->Form->control('tel', array('label' => __('Telefon', true)));
echo $this->Form->control('kontonummer', array('label' => __('Kontonummer', true)));
echo $this->Form->control('bankleitzahl', array('label' => __('Bankleitzahl', true)));
echo $this->Form->control('lastschrift', array('label' => __('Lastschrift', true)));
echo $this->Form->control('detail', array('label' => __('Weitere Details', true)));
echo $this->Form->control('betreuer_anrede', array('label' => __('Betreuer Anrede', true)));
echo $this->Form->control('betreuer_name', array('label' => __('Betreuer Name', true)));
echo $this->Form->control('betreuer_strasse', array('label' => __('Betreuer Straße', true)));
echo $this->Form->control('betreuer_plz', array('label' => __('Betreuer PLZ', true)));
echo $this->Form->control('betreuer_ort', array('label' => __('Betreuer Ort', true)));
echo $this->Form->control('betreuer_on_bill', array('label' => __('Betreuer soll auf der Rechnung stehen', true)));
?>
</fieldset>
<?= $this->Form->button(__('Bestätigen')) ?>
<?= $this->Form->end() ?>
</div>
CustomersTable.php
class CustomersTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('customers');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('Tours', [
'foreignKey' => 'tour_id'
]);
$this->hasMany('Bills', [
'foreignKey' => 'customer_id'
]);
$this->hasMany('Orders', [
'foreignKey' => 'customer_id'
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmptyString('id', 'create');
$validator
->integer('order')
->allowEmptyString('order');
$validator
->scalar('kdnr')
->maxLength('kdnr', 45)
->allowEmptyString('kdnr');
$validator
->scalar('debinr')
->maxLength('debinr', 31)
->allowEmptyString('debinr');
$validator
->scalar('anrede')
->maxLength('anrede', 45)
->allowEmptyString('anrede');
$validator
->scalar('name')
->maxLength('name', 45)
->allowEmptyString('name');
$validator
->scalar('strasse')
->maxLength('strasse', 45)
->allowEmptyString('strasse');
$validator
->integer('plz')
->allowEmptyString('plz');
$validator
->scalar('ort')
->maxLength('ort', 45)
->allowEmptyString('ort');
$validator
->scalar('tel')
->maxLength('tel', 45)
->allowEmptyString('tel');
$validator
->boolean('lastschrift')
->allowEmptyString('lastschrift');
$validator
->scalar('kontonummer')
->maxLength('kontonummer', 32)
->allowEmptyString('kontonummer');
$validator
->integer('bankleitzahl')
->maxLength('bankleitzahl', 32)
->allowEmptyString('bankleitzahl');
$validator
->scalar('detail')
->allowEmptyString('detail');
$validator
->scalar('betreuer_anrede')
->maxLength('betreuer_anrede', 45)
->allowEmptyString('betreuer_anrede');
$validator
->scalar('betreuer_name')
->maxLength('betreuer_name', 45)
->allowEmptyString('betreuer_name');
$validator
->scalar('betreuer_strasse')
->maxLength('betreuer_strasse', 45)
->allowEmptyString('betreuer_strasse');
$validator
->integer('betreuer_plz')
->allowEmptyString('betreuer_plz');
$validator
->scalar('betreuer_ort')
->maxLength('betreuer_ort', 45)
->allowEmptyString('betreuer_ort');
$validator
->boolean('betreuer_on_bill')
->allowEmptyString('betreuer_on_bill');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['tour_id'], 'Tours'));
return $rules;
}
}
I hope I explained my Goal well enough and didn't forgot something. I'm still learning so if I forogt something just let me know and I will edit my Question.