Welcome Guest, Not a member yet? Register   Sign In
in_unique Validation Rule Help
#1

Hello! 
I am building a section for people to update their email addresses along with their name. I have a validation rule that checks that the email address entered is unique but I also need to ensure that the error doesn't happen if the email hasn't changed. I have came up with this rule based on the docs but it just throws the error.

PHP Code:
'email'=> 'required|valid_email|is_unique[users.email, users.email, '.$existingUserDetails['email'].']'

I tried using {email} instead of hard coding the value but throws an error: The placeholder field cannot use placeholder: email

Just trying to avoid having to roll my own rule for this as is_unique ticks all the boxes.
Reply
#2

(This post was last modified: 11-29-2023, 01:42 PM by grimpirate.)

This example https://codeigniter4.github.io/userguide...aceholders shows exactly what you're attempting to achieve. The only possible difference I see is that your statement for is_unique should be is_unique[users.email,email,{email}]. Though you should probably be using the user id instead to ignore the user's present email (as per the example).

In a more general sense. The user is opting to change their email. It doesn't matter what their previous email is. Whether they update it to a new value or the same value is irrelevant. The only thing that requires validation is that they aren't trying to use someone else's registered email.
Reply
#3

(11-29-2023, 01:39 PM)grimpirate Wrote: This example https://codeigniter4.github.io/userguide...aceholders shows exactly what you're attempting to achieve. The only possible difference I see is that your statement for is_unique should be is_unique[users.email,email,{email}]. Though you should probably be using the user id instead to ignore the user's present email (as per the example).

In a more general sense. The user is opting to change their email. It doesn't matter what their previous email is. Whether they update it to a new value or the same value is irrelevant. The only thing that requires validation is that they aren't trying to use someone else's registered email.

Sorry for the delay in getting back to this! So the ID isn't part of the form so I can't use the example unless you can pass in the ID?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB