Problem:
Restrict CRED form to one profile post per user, prevent duplicate submissions from back-button, fix Edit button not showing form in Bricks.
Solution:
Place create form inside View's [wpv-no-items-found] section (View filtered by author = current user). Add cred_form_validate for server-side duplicate check:
add_filter('cred_form_validate', 'profile_exists_validation', 10, 2);
function profile_exists_validation($error_fields, $form_data) {
global $current_user;
list($fields, $errors) = $error_fields;
if ($form_data['id'] == 12345) {
$args = array(
'author' => $current_user->ID,
'posts_per_page' => 1,
'post_type' => 'profile',
);
profiles=getposts(profiles = get_posts(
profiles=getposts(args);
if (sizeof($profiles) > 0) {
$errors['post_title'] = 'A profile already exists, so you cannot create another one.';
}
}
return array($fields, $errors);
}Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#toolset-edit-post-link
https://toolset.com/course-lesson/front-end-forms-for-editing-content/
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.
This topic contains 3 replies, has 1 voice.
Last updated by 1 week, 2 days ago.
Assisted by: Christopher Amirian.