Update Unique fields

By: Jay Mac | Asked: 05/13/2023
ForumsCategory: General questionsUpdate Unique fields
Jay Mac asked 11 months ago
I have two email addresses in my form one is the user id and one is a backup email. I want both to be unique but I want the user to be able to change the backup email if it has changed. If I put the unique checkbox checked it appears formidable treats this as a brand new email address and checks it against all other email addresses including the users current email address and then triggers an error if they don't change it to a new address. Is there any way to get around this?   Their AI assistant suggested a great conditional logic solution, unfortunately the solution requires features that are not available. 
Victor Font replied 11 months ago

I'm not sure there's an answer to your question. I've been using Formidable for a very long time, and when I've had a requirement for a unique field, it just always works. I have no idea how Formidable tests for uniqueness. We're Community Volunteers and use Formidable as end users, just like yourself. This question is something I think only a developer intimately familiar with Formidable's Core code can shed some light on.

What did the AI suggest? What features are not available? Maybe we can help with that if there are references to hooks.

Jay Mac replied 11 months ago

Thank you Victor. The userid that is set via the email is the personal email like a gmail account. The assumption is that people will not change that very often. I leave that alone. I add a second email their corporate or organization email that is stored in user_meta. They can change that as they switch jobs. I still want that email to be unique so it should be checked for duplicates. If I set unique and recall it from user_meta in a profile update form and the user does not change it the form will not submit saying the email must be unique. I thnk the AI assistant was confused but it did have a great answer using conditional logic options that are not on my form:

Maybe this quick answer from our AI Assistant will help?: To allow the user to not update a unique field, you can use a conditional logic rule in your form that checks if the unique field is already filled with the user's email address. If it is, then the field should be set to read-only, so that the user cannot change it.
Here are the steps to set up this conditional logic rule:
1. Go to the form builder and select the field that has the unique option checked.
2. Click on the "Advanced" tab in the field settings.
3. Scroll down to the "Conditional Logic" section and click on "Add Rule".
4. In the "If" section, select "Field" and choose the field that contains the user's email address.
5. In the "Is" section, select "Filled" to check if the user's email address is already filled in the field.
6. In the "Then" section, select "Field" and choose the unique field that you want to make read-only.
7. In the "Action" section, select "Read-only" to make the field read-only if the user's email address is already filled in the field.
8. Save the form and test it to make sure that the unique field is read-only when the user's email address is already filled in the field.
By setting the unique field to read-only when the user's email address is already filled in the field, you are allowing the user to not update that field while still maintaining the uniqueness constraint.

2 Answers
Walter JonesWalter Jones answered 11 months ago
im assuming your using the FF Registration Addon right? And one of your email addresses if your username field?  I think the issue your running into is that once you set fields to work with the Addon, the Addon basically takes control over the fields functionality, I have had this happen where I am trying to load default values from one form to another passing entry key.  Im not sure there is a solution, unless you use another field for the username name.
Jay Mac replied 11 months ago

I am using the FF Registration Addon and yes the username field is the personal email and that is the one I am not allowing them to update (readonly). I have validated the org email is in the wp_user_meta table and the personal email that is the username is the wp_users table.

Jay Mac answered 11 months ago
I found the answer to this problem if anyone is interested:   add_filter('frm_validate_field_entry', 'check_mentor_email', 10, 3); function check_mentor_email($errors, $posted_field, $posted_value){ $mentordemailid = FrmField::get_id_by_key('mentoremail0010'); if($posted_field->id == $mentordemailid) { if(empty($posted_value)) { /* email is not required so this is good*/ } else { $mentoremail = sanitize_email( $_POST['item_meta'][$mentordemailid]); //  if ( is_email( $mentoremail ) && email_exists( $mentoremail ) ) {                           $errors['field'. $posted_field->id ] = 'This email address is registered, please try another one or leave blank.';                          } } } return $errors; }

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community