Skip Navigation

[Resolved] Compare current Form data with stored data

This thread is resolved. Here is a description of the problem and solution.

Problem:
Can we compare data that an user entered in a CRED Form before submit, with the data already stored in the Database?

Solution:
Theoretically yes.
But it requires Custom Code:
https://toolset.com/forums/topic/cred-form-submission/#post-573596

You will get the data from the $_POST and compare it as example on submit, or similar, with the data in the Database.

This support ticket is created 7 years, 1 month ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by alanS3341 7 years, 1 month ago.

Assisted by: Beda.

Author
Posts
#573396

Hello, I was wondering if there is a way for a "registered user" to fill in a front end form (without logging in) and for the form submit action to check that they are registered to allow form submission (to avoid registered users from having to log in to submit a form each time) based on their user name and email? I have tried using gravity forms but with no luck. I have set up a redirect for "subscribers" but there is only one option for a redirect url. So! The user scans a QR code to check in to a location here (just as an example): hidden link

But, I have a form that says if you are not "logged in" or registered then log in or register. But when the registered user log's in they are taken to the admin panel instead of the actual form page, because the redirect doesn't allow multiple redirects and also even when logged in it takes you back the the admin panel instead of the url as the link url doesn't check if you are already logged in and load the form.

So is there a way for registered users, to submit a form where the submit button only shows of the user name and email are checked against registered users and then the submit button is shown "after" the email and user name are checked to authenticate that they are registered...

Sorry for all of that, it's kinda complicated.

Regards

Al

#573596

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.

#575048

Sorry Beda,

I have been busy with some other things. I have marked it as resolved until I can test it. If I have any other questions I will start a new ticket. Thanks for all your help, I really appreciate it.

Regards
Al