check for unique on create but not on update

check for unique on create but not on update

schiefersoftschiefersoft Posts: 7Questions: 2Answers: 2

I have a field in the Editor:

Field::inst('users.username')->validator('Validate::notEmpty')->validator('Validate::unique'),

this works fine when I add a user.
But when I update the user the red error message "This field must have a unique value" comes on the field Username
How can I check the field "users.username" for beeing unique only at the create ?
Thanks

This question has an accepted answers - jump to answer

Answers

  • schiefersoftschiefersoft Posts: 7Questions: 2Answers: 2
    Answer ✓

    found the solution by my self:

    $username = Field::inst('users.username');
    if (Editor::action( $_POST ) === Editor::ACTION_CREATE) 
    {
        $username->validator('Validate::notEmpty')->validator('Validate::unique');
    }
    if (Editor::action( $_POST ) === Editor::ACTION_EDIT) 
    {
        $username->set(Field::SET_EDIT);
    }
    
  • yzakaria86yzakaria86 Posts: 2Questions: 0Answers: 0

    but where should I place $username?

  • yzakaria86yzakaria86 Posts: 2Questions: 0Answers: 0

    I found out :)
    thanks

This discussion has been closed.