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;
//validate if specific form
if ($form_data['id']==283)
{
//check my_field value
if (strlen(trim($fields['wpcf-id-number']['value'])) != 13 )
{
//set error message for my_field
$errors['wpcf-id-number']='Please enter exact 13 digits';
}
}
//return result
return array($fields,$errors);
}
Unfortunately it's not working for me. In my case I have characters instead of digits and I need to implement this code on multiple fields.
wpcf-artist-1 -->min. 250 characters otherwise the form can't be submitted
wpcf-artist-2 ->min. 250 characters
_post_excerpt ->min. 250 characters
*** 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.
wpcf-artist-1 -->user should input min. 250 characters otherwise the form can't be submitted
wpcf-artist-2 ->user should input min. 250 characters otherwise the form can't be submitted
_post_excerpt ->user should input min. 250 characters otherwise the form can't be submitted
I've modified the code in your functions.php file as given under:
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;
//validate if specific form
if ($form_data['id']==118)
{
//check my_field value
if (strlen(trim($fields['wpcf-artist-1']['value'])) > 50 ){
//set error message for my_field
$errors['wpcf-artist-1']='Please enter exact 50 characters';
}else if (strlen(trim($fields['wpcf-artist-2']['value'])) > 50 ){
//set error message for my_field
$errors['wpcf-artist-2']='Please enter exact 50 characters';
}else if (strlen(trim($_POST['post_content'])) > 250 ){
//set error message for my_field
$errors['post_content']='Please enter exact 250 characters';
}
}
//return result
return array($fields,$errors);
}
Could you please check now and confirm your issue is resolved.
I am using the following code to allow users to set the post status of their post on the frontend.
If the user wants to save the post as a draft the function you shared above should not be triggered. Only if the user want's to save his post as published.
How would I integrate this functionality with your code snippet?
[cred_generic_field field='post_status' type='select' class='choose_post_status' urlparam='']
{
"required":0,
"validate_format":0,
"default":["[wpv-post-status]"],
"options":[
{"value":"draft","label":"Save As Draft"},
{"value":"pending","label":"Publish For Review"}
]
}
[/cred_generic_field]
* Set post status via CRED generic field
*/
function customize_cred_form_118( $post_id, $form_data ){
if ( isset( $_POST['post_status'] ) ) {
$updates = array(
'ID' => $post_id,
'post_status' => $_POST['post_status']
);
wp_update_post( $updates );
}
}
add_action( 'cred_save_data_118', 'customize_cred_form_118', 10, 2 );