Ich muss ein Formular validieren und ich weiß nicht genau, wie ich das tun kann. Ich habe versucht, in Model/Users.php und Model/Table/UserTables.php und nichts zu validieren.CakePHP 3: Formular validieren
Jemand kann mir helfen?
register.ctp
<br>
<div class="index large-4 medium-4 large-offset-4 medium-offset-4 columns">
<div class="panel">
<h2 class="text-center">Cadastro</h2>
<?= $this->Form->create(); ?>
<?= $this->Form->input('nome'); ?>
<?= $this->Form->input('email'); ?>
<?= $this->Form->input('password'); ?>
<?= $this->Form->submit('Cadastrar', array('class' => 'button')); ?>
<?= $this->Form->end(); ?>
</div>
</div>
ich exaclty weiß nicht, wo ich sagen darf:
public $validate = array(
//campo que deve ser validado
‘nome’ => array(
//alias da validação
‘notempty’ => array(
‘rule’=>’notempty’,//validação para não aceitar vazio
‘message’=>”Você deve preencher este campo”//erro
)
),
‘idade’ => array(
‘notempty’ => array(
‘rule’ => ‘notempty’,
‘message’ => ‘Você deve preencher este campo’
),
‘numeric’ => array(
‘rule’ => ‘numeric’,
‘message’ => ‘Você deve preencher este campo’
)
)
);
}
Validierung auf UsersTable.php funktioniert nur mit "add" Form:
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->requirePresence('nome', 'create')
->notEmpty('nome');
$validator
->email('email')
->requirePresence('email', 'create')
->notEmpty('email');
$validator
->requirePresence('password', 'create')
->notEmpty('password');
return $validator;
}
hinzufügen kann ich zieh das an Modell/Entity/User.p HP Ordner? Danke für die Antwort. – VitorTech
Sie möchten es zu dem Modell hinzufügen, in dem Sie speichern. Fügen Sie es also dem Benutzermodell hinzu, wenn Sie in der Benutzertabelle speichern. – bill
Ich kann nicht validieren. Das Formular "Hinzufügen" funktioniert zwar, aber mein Registrierungsformular funktioniert nicht. Ich bin neu bei CakePHP. – VitorTech