Due to using the new release version of Toolset map, I have to change my user form to post form, because Toolset map plugin does not yet support usermeta currently, and before I have opened a similar ticket https://toolset.com/forums/topic/limit-the-count-of-submission-form-one-post-per-role/. But I don't know what I did wrong, the user I specific role is still able to submit more than one post now.
1. the post slug: house
2. user role I would limit: guest
3. The cred form which is used to create new post: form ID is 20; note: because there is a too long form, so I had split 3 steps form. the first form is used to create new content, and third form is used to publish the post.
4. setting up a single line custom type field and adding it into the first form, it is used to validate the form, the field name is validation field test.
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==20)
{
$user = get_current_user_id();
$user_post_count = count_user_posts( $user , 'house' );
$user_data = get_userdata($user);
$user_role = $user_data->roles;
if ( $user_role[0] == 'guest' && $user_post_count > 0)
{
//set error message for my_field
$errors['wpcf-validation-field-test']='Only 1 post per user is allowed';
}
}
//return result
return array($fields,$errors);
}
but it is still not working, does it cause by the 3 steps form I set up?
1.could you please help check what I did wrong?
2. I guess the sentence above that will be shown up on a modal box when the user click the submit button. How I can add a button to lead user to another page?
Thank you so much!
Follow-up, is it possible to use it with WPML to automatically generate multilingual posts like this https://toolset.com/forums/topic/cred-front-end-submission-form-of-multilingual-sites-with-wpml/#post-592405. I am afraid if the code has a loophole, in case users create new post in another language site and default language site, and wasn't limited by multilingual site.
Dear Jeffrey,
Q1) Due to using the new release version of Toolset map ...
There is a misunderstand, with the latest version of Toolset Map plugin, you can setup the custom user address field too.
See our document:
https://toolset.com/documentation/user-guides/display-on-google-maps/
An Address field type, to use as a custom field or user field
So, I don't think you need to switch to post form.
Q2) Follow-up, is it possible to use it with WPML to automatically generate multilingual posts ...
Since it is a new custom codes question, please create new thread for it, and describe detail steps to duplicate same problem, what kind of result do you want to achieve, that will help othere users to find the answers.
Hi Luo, Thank you so much for you response. I knew this issue was more complex. but in my project, such like vacation rental, One owner per house, all of owner and house information is equal to profile information. but these are very important as well. I found that many of your developing and developed features didn't aim usermeta. this is the reason why I decided to change user forms to post forms. that doesn't mean Toolset is not good enough, I really love your plugins, indeed, it is very very useful to me. however I know your developing team have to focus on developing more popular features. The new release google map version has a great feature which only works with type field. https://toolset.com/forums/topic/google-map-distance-feature-of-new-lease-version-seems-not-working-for-usermeta/#post-600767 https://toolset.com/2017/12/toolset-maps-1-4-with-geolocation-filtering-by-distance-and-custom-map-styles/#comment-332627
when you have spare time, and would like to solve this, it is not pressing business. 🙂
Since it is a custom codes problem, please provide a test site, and fill below private detail box with login details and FTP access, also point out the problem page URL and CRED form URL, and where I can edit you PHP codes, I need a live website to test and debug, thanks
Hi Luo,
Just want to hold this ticket, because I have to adjust something before you do. and please send the private link to me again, Thank you so much for the help!
As your request, the private detail box enabled again, please check the post as I mentioned above:
https://toolset.com/forums/topic/limiting-one-post-per-user-not-working/#post-607415