Previously, I asked the following question. When I'am in the edit-screen and I set the value "Done" in the field "Project_status", is it then possible that I can force me to change the field "Afgehandeld" to the value "Arjan" automaticly.
Because I was not able to add my code to the provided answeres, I asked it again, but now with the code that I already have.
This code is unfortunily not working
Who can further help this newbie?
Thanks in advance.
<?php
/* src/template/projecten/index.ctp */
foreach ($projecten as $DB_inhoud):
...
...
echo $DB_inhoud->Project_status;
echo $DB_inhoud->Opgeleverd;
...
...
endforeach;
?>
<?php
/* src/template/projecten/edit.ctp */
...
echo $this->Form->select('Project_status', $status, ['escape' => true]);
echo $this->Form->input('Opgeleverd',['label' => false]);
...
...
?>
<?php
/* src/Model/Table/ProjectenTable.php */
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\ORM\RulesChecker;
Class ProjectenTable extends Table
{
Public function initialize (array $config)
{
$this->addBehavior('Timestamp');
}
public function customValidationMethod($check, array $context)
{
$validator->add('Projecten->Opgeleverd', 'custom',
['rule' => function ($value, $context)
{
echo $context;
if ($context['Projecten->Project_status'] == "100. Project opgeleverd")
{
return $value == "Arjan";
}
return true;
},
'message' => 'Error message'
]);
}
}