Skip Navigation

[Resuelto] Need to validate unique mail values in post field

This support ticket is created hace 1 año, 2 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Este tema contiene 7 respuestas, tiene 3 mensajes.

Última actualización por Minesh hace 1 año, 2 meses.

Asistido por: Minesh.

Autor
Mensajes
#2644157
Captura de pantalla 2023-09-14 123357.png

Tell us what you are trying to do?
im trying to build a membership site, now have the respective products and membership yet, but i have a trouble with validation of unique email, that is not work,

the steps of register is:
-create an account
-log in
-send form for register a new entry of "base de datos" custom post

the entry must be unique for each of the users, and must be validated by the email field

Is there any documentation that you are following?

i follow this post https://toolset.com/forums/topic/need-to-validate-unique-values-in-post-field/#post-1201756
i need to know how to solve this

Is there a similar example that we can see?

What is the link to your site?
enlace oculto

#2644221

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Have you tried the validation hook shared with the reference ticket you shared?

If yes - what issue you are facing?
- have you also tried to replace the form ID and your custom field slug as well as post type?

Can you please share bit more details where exactly you stuck and where you need help with and problem URL and admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2644971

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where I can see the form to validate the email?

#2645061

of course enlace oculto

#2645343

Thank you for sharing these details.

Just wanted to let you know that Minesh is on holiday today.

He'll be back tomorrow and will be able to follow up on this ticket, accordingly.

Thank you for your patience.

#2645603

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please check now:

I've adjusted the code snipped as given under:
- enlace oculto

add_filter('cred_form_validate','func_validate_custom_email',10,2);
function func_validate_custom_email($error_fields, $form_data){
  
    //field data are field values and errors
 	list($fields,$errors)=$error_fields;
  
     if ($form_data['id']==54610){
          
        $args = array(
                    'meta_query' => array(
                        array('key' => 'wpcf-email-bd',
                              'value' => $_POST['wpcf-email-bd']
                            )),
                    'post_type' => 'base-de-datos-alas',
                    'post_status' => array('publish', 'pending', 'private'),
                    'posts_per_page' => -1
                    );
            $posts = get_posts($args);
  
  
         if (count($posts) > 0){
  
            //set error message for my_field
 			$errors['wpcf-email-bd']='This E-mail already registered.';
  
        }
       
    }
  
    return array($fields,$errors);
  
}

The reason why it was not working because you have a private posts and by default get_post function checks and return the publish posts. So I've added the post status argument to get_post argument as you can see with the above code:

 'post_status' => array('publish', 'pending', 'private'),

Now, when I tested I can see it returns the email validation error when there is email exists.

#2646181

perfect! the email verification is done!, now we have another peition

can i change user type when they send a post form?

#2646187

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the original question reported.

May I kindly ask you to open a new ticket with every new question you may have. That would be really helpful.

You're welcome to mark resolve this ticket.