In Model/table we have a membres.php with that statement:
$validator
->date(‘date_de_naissance’)
->requirePresence(‘date_de_naissance’, ‘create’, ‘Une date de naissance est requise.’)
->notEmpty(‘date_de_naissance’, true, ‘La date de naissance ne peut pas être vide.’);
we want to add extra validation for date_de_naissance > 49.
And at entry level (template): filename.ctp:
Hello Graziel,
I do not know where to put or set the following variable:
$atLeast49 = (new Date())->subYears(49)->year;
I have a MembresController.php and a ajouter.ctp so a MembresTable.php
Here is the link: https://1drv.ms/u/s!AtxUdY_g_iSIlAvcb6aIp0AMcBmk?e=3Zl5M9
Thanks for helping
This validation still not working, maybe I did not send enough info:
*/
class MembresTable extends Table {
/**
* Méthode initialize.
* @param array $config La configuration de la table.
* @return void
*/
public function initialize(array $config) {
parent::initialize($config);
$this->addBehavior('Timestamp');
$this->belongsTo('Types', ['joinType' => 'INNER']);
$this->belongsTo('Utilisateurs', ['foreignKey' => 'ajoute_par_utilisateur_id', 'joinType' => 'INNER']);
$this->belongsTo('Utilisateurs', ['foreignKey' => 'modifie_par_utilisateur_id', 'joinType' => 'INNER']);
$this->hasMany('Inscriptions');
$this->hasMany('ListesAttente');
$this->belongsToMany('Activites', ['joinTable' => 'inscriptions']);
}
public function checkOver50($check) {
$this->$bday = strtotime($check['date_de_naissance']);
if (time() < strtotime('-49 years', $bday)) return false;
return true;
here is what I find in MembresTable.php
$validator
->date(‘date_de_naissance’)
->requirePresence(‘date_de_naissance’, ‘create’, ‘Une date de naissance est requise.’)
->notEmpty(‘date_de_naissance’, true, ‘La date de naissance ne peut pas être vide.’)
->add(‘deb’,‘age’), [
‘rule’ => [checkOver50],
‘message’ => ‘Un member ou non-membre doit avoir 50 ans ou plus’
]);