Issue
I have a form on a .ctp which has multiple input fields. One of those input fields is an type="email" field. When submitting, that field is not important for me and i tried many ways of allowing that field to remain empty but it still bugs me with an error that "This value is already in use". Below is how my input look like in the page, with the given error:
And this is how my input looks like in the .ctp:
<tr style="height:30px;">
<td style="width: 160px;"><?= 'E-mail' ?></td>
<td>
<?= $this->Form->input('email',['empty' => false, 'label' => false, 'required' => false]); ?>
</td>
<td style="width:75px;"></td>
<td class="edit_hints" style="border-bottom: 1px solid lightgrey;">Completează cu adresa de e-mail a persoanei de contact.</td>
</tr>
And this is what my $validator looks like:
$validator
->email('email')
->allowEmpty('email')
->requirePresence('email', false);
As you can see, i have tried everything I have researched and this problem still bugs me. What I am thinking is, that the email validator might find the empty value in another row in my db and it may resemble this error. Is there any way to fix that?
Solution
Make sure that you don´t have buildRules like this in your table
public function buildRules(RulesChecker $rules) {
$rules->add($rules->isUnique(['email']));
return $rules;
}
Answered By - Jacek B Budzynski
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.