When a user is not logged in, in WordPress this user is a Guest.
A guest leaves no trace on your Website usually. Especially, we cannot track this user's data, as the user does not exist at this moment, it is a Guest.
Now, using data that the user submits to check if this exists in the database is possible.
But, the chance that an user accidentally submits the same Email as from an existing user, by mistake, for example, is great.
How would you handle this?
To check and compare this Data, you would need to hook into the CRED Form the moment before or during the data is saved.
This can be done with the CRED API:
https://toolset.com/documentation/programmer-reference/cred-api/
Especially the Hook https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data.
With this hook you can fire your Custom code which will use PHP and the WordPress API to:
- get the submitted data from the form (it's in the $_POST hidden link)
- get the entire Users Data (for example, target the emails: hidden link)
- Compare the Form Data (from $_POST) with the data from the above code ($author_info->user_email) and if there is a match, perform an action to let the user Login, or similar.
This requires Custom Code, that we cannot support here, but we could refer to the certified partners here:
https://toolset.com/consultant/
Another approach, is to hide the Submit button with a CRED Conditional, as you suggest.
But also here you need Custom Code.
You need to get all the possible Emails from all users, and compare them in the conditional.
This seems complex but is quite simple.
1. Wrap your CRED Submit Button in this conditional:
[cred_show_group if="[compare_guest_data]" mode='fade-slide']
//Your CRED button here
[/cred_show_group]
2. Add this Custom ShortCode (please adapt if needed) to your Theme's Functions File:
[php]
function compare_guest_data($args){
//get all Users Data. For args consult https://codex.wordpress.org/Function_Reference/get_users
$blogusers = get_users();
//get each single existing users data
foreach ( $blogusers as $user ) {
//Escape Email Field. For other data consult https://codex.wordpress.org/Function_Reference/get_users
$user_mail = esc_html( $user->user_email );
//build the conditional syntax for each user data
//IMPRTANT. replace post_title with the field you want compared!
$data[] = "($(post_title) eq '$user_mail' )";
}
//concatenate the conditons with OR statement. can be also AND
$out = join(" OR ",$data);
//Return for usage in ShortCode
return $out;
}
//Register shortcode
add_shortcode('compare_guest_data', 'compare_guest_data');
Edit it as adequate to your needs
3. Test the form, it should now only show the submit button once your field of choice is filled with an existin email.
Of course, it can also be done opposite, if there is a match, hide the button.