Hello, I need to disallow user to save data with toolset form, when he already sent one.
I have done some basic things like disallow displaying form if user post count is more than 1. But when user sent form and then go back in browser, form stays visible. So I would love to use the function else when user send form.
So is it possible to use this somehow with Toolset form?
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
//validate if specific form
if ($form_data['id']==178)
{
$user_post_count = count( get_posts( array(
'post_type' => 'kviz',
'author' => get_current_user_id(),
) ) );
if ($user_post_count >= 1) {
$errors['']='Kvíz už jsi vyplnil. Momentálně to lze pouze jednou.';
}
}
return array($fields,$errors);
}
?>
And I don't know what to put inside the error? Because it is not a validation of any specific field.
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
//validate if specific form
if ($form_data['id']==178)
{
$user_post_count = count( get_posts( array(
'post_type' => 'kviz',
'author' => get_current_user_id(),
) ) );
if ($user_post_count >= 1) {
$errors['xxxxx']='Kvíz už jsi vyplnil. Momentálně to lze pouze jednou.';
}
}
return array($fields,$errors);
}
I am not sure, what to put inside the $errors. I am not validating any fields, but if user have posts..
Indeed, the error needs to be set against a field. Try using default fields, such as "post_title" or "post_content". I know, that's not as pretty as you would like to have, but it could serve to get the validation complete.
$errors['post_title']='Kvíz už jsi vyplnil. Momentálně to lze pouze jednou.';
// or
$errors['post_content']='Kvíz už jsi vyplnil. Momentálně to lze pouze jednou.';
If that's not enough, let me know and I'll escalate it to our 2nd Tier for further analysis. He may suggest another solution or check with the developers, but that could take some time before the request is answered.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.