Hello, I am currently still using version 1.9.3.1, because I don't have a lot of time dealing with that issue. Sorry for the late reply.
Here are the code components:
/*******************************************************/
//create form && edit form
/*******************************************************/
//post content substitute 98 && 216
add_action('cred_save_data', 'my_save_content',10,2);
function my_save_content($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==98 || 216)
{
if (isset($_POST['post_content_substitute']))
{
// add it to saved post meta
$my_post = array(
'ID' => $post_id,
'post_content' => $_POST['post_content_substitute']
);
// Update the post into the database
wp_update_post( $my_post );
}
}
}
//copy post content substitute content to excerpt field 98 && 216
add_action('cred_save_data', 'my_save_excerpt',10,2);
function my_save_excerpt($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==98 || 216)
{
if (isset($_POST['post_content_substitute']))
{
// add it to saved post meta
$my_post = array(
'ID' => $post_id,
'post_excerpt' => $_POST['post_content_substitute']
);
// Update the post into the database
wp_update_post( $my_post );
}
}
}
//validate form characters 98 && 216
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']==98 || 216){
if( ($_POST['post_status']!='draft') ) {
//check my_field value
if (strlen(trim($fields['post_content_substitute']['value'])) < 250 ){
//set error message for my_field
$errors['post_content_substitute']='Please enter at least 250 characters in Step 3 or save your post as a draft to edit it later';
}
}
}
//return result
return array($fields,$errors);
}
And:
Create Form
[cred_generic_field field='post_content_substitute' type='textarea' class='new-textarea' urlparam='' placeholder='Write a few words...']
{
"required":1,
"validate_format":0,
"default":""
}
[/cred_generic_field]
Edit Form:
[cred_generic_field field='post_content_substitute' type='textarea' class='new-textarea' urlparam='' placeholder='Write a few words...']
{
"required":1,
"validate_format":0,
"default":"[wpv-post-excerpt format="noautop"]",
"persist":1
}
[/cred_generic_field]
And here are the related tickets from the past I've created:
https://toolset.com/forums/topic/generic-field-used-as-substitute-for-post_content-field-is-not-showing-content/
https://toolset.com/forums/topic/make-excerpt-fields-required/
https://toolset.com/forums/topic/cred-post-excerpt-and-post-content/
- Can you explain in detail how the "Edit" CRED form is added to the site - is it placed in a View, or in a Content Template or Template Layout, is it in a custom Page, etc.?
I created a page called: Form Edit
And placed this shortcode in the post_content field [cred_form form='form-edit' form_name='Form Edit' post='[wpv-search-term param="post_id"]']
Hope this can help you to solve the problem.
I am trying to set up a staging site soon.
Regards,
Nick