PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 18, 2022

[FIXED] Error when leaving an empty email input field clear

 February 18, 2022     cakephp, cakephp-3.0, html, php     No comments   

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:

form 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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing