Home › Toolset Professional Support › [Resolved] CHECK POSTED DATA TO AVOID DUPLICATED ENTRIES
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 |
---|---|---|---|---|---|---|
- | 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)
Tagged: Content-submission forms, Toolset Forms
Related documentation:
This topic contains 16 replies, has 2 voices.
Last updated by Minesh 7 years ago.
Assisted by: Minesh.
Tell us what you are trying to do?:
I want to know is there is any way to avoid duplicates. I want to check if some fields like "birthdate" are equal to older post to avoid duplicates. I am using last version of all plugins.
Is there any documentation that you are following?
I didn't found anything related to this
Is there a similar example that we can see?
Yes. Let me explain an example:
User go a Cred form on the frontend. When he clicks on submit, the cred from should check if the field "birthdate" are equal to older post(must check will all older post). If any older post have the same "birdate" then will see a warning message or something else, if not will be saved as usual.
What is the link to your site?
Hello. Thank you for contacting the Toolset support.
Well - CRED offers hook for validating the post before you save it. You can use CRED hook cred_form_validate to validate your form.
More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
You need to add your custom logic to check if any post exists equal to "birthdate" if yes, you should throw error message otherwise save the post.
thanks for your reply but still need a little help. I will be more than glad if you help with a little code
my cred form id is '79'
'my field to compare is 'birthday'
I wrote a sample (unfinished ) code,so please help me 🙂
----------
add_filter('cred_form_validate','my_validation',10,2); function my_validation($error_fields, $form_data) { //field data are field values and errors list($fields,$errors)=$error_fields; //uncomment this if you want to print the field values //print_r($fields); //validate if specific form if ($form_data['id']==79) { //check if birthday value is already on the database if ( birthday data is already on the database) { //set error message for my_field $errors['wpcf-birthday']='Wrong Value'; } } //return result return array($fields,$errors); }
Well - I need to know for which post type we need to check the birthday field value is exists or not?
is birthdate field is created using Types? how you added birthday field to CRED form as datepicker?
Is it possible for you to share problem URL?
You need to use kind of code as given under to fetch the records that equals the post meta key 'wpcf-birthday' - but I need exact information about post type, field name etc...etc to guide you with exact solution.
$args = array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => 'wpcf-birthday', 'value' => $_POST['birthday'][''], ) ) ); $postslist = get_posts( $args );
Hi Minesh,
You are right:
-Post type it's created with types.
-post_type=upn
-the slug of this field is "fnacimiento" (birthday on english)
Please give me a private box to pur the URL and login details for you
Regards
Please do not forget to send problem URL where you've added the CRED form.
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Well - when I try to access wp-admin or even I try to load the site URL you shared its showing me "Forbidden" error message.
You don't have permission to access /wp-admin/ on this server. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Could you please do needful so that the site should start to work at this end.
You are right.
Please try again
Regards
Well - still, I can able to see login page but when I tried to login the page is blocked.
Could you please test once and send me working access details.
So sorry, I deactived all security layers and tried using another IP and it works 100% sure
Thanks
Thank you - Now, wp-admin is working fine.
I would like to know where you've added the CRED form UPNs (ID: 79)? Could you please share link of that page?
Yes just go to pages, and you will see. The page with that Creed form is the page post=77, so
wp-admin/post.php?post=77&action=edit
Regards
The code snippet plugin is not working with the CRED hook so I've added the following code to your current theme's functions.php file:
add_filter('cred_form_validate','func_validate_birthdate',10,2); function func_validate_birthdate($error_fields, $form_data){ //field data are field values and errors list($fields,$errors)=$error_fields; //uncomment this if you want to print the field values //print_r($fields); //validate if specific form if ($form_data['id']==79){ $args = array( 'meta_query' => array( array('key' => 'wpcf-fnacimiento', 'value' => $_POST['wpcf-fnacimiento']['timestamp'] )), 'post_type' => 'upn', 'posts_per_page' => -1 ); $posts = get_posts($args); //check if birthday value is already on the database if (count($posts) > 0){ //set error message for my_field $errors['wpcf-fnacimiento']='Wrong Value'; } } //return result return array($fields,$errors); }
Could you please confirm its working for at your end as well.
It works nice! Thank you so much for your patience. However is not exactlly what I ask (maybe I didn't explain well, sorry in advance)
The page has to show a warning(it does) , the purpose is to show that warning, and later that let the user send information anyway.
I moved your code to Snippets --> /wp-admin/admin.php?page=edit-snippet&id=3