Skip Navigation

[Resolved] WYSIWYG generic field form problem

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 19 replies, has 2 voices.

Last updated by Minesh 1 year, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2628077

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can use the Toolset form hook "cred_before_save_data" and assign the value to your desired field.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

For example - I've added the following code to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
- hidden link

add_action('cred_before_save_data', 'func_save_content_for_generic_field',10,1);
function func_save_content_for_generic_field($form_data) {
    // if a specific form
    if ($form_data['id']==198) {
		
        if (isset($_POST['post_content_accepted']) and !empty($_POST['post_content_accepted']) ) {
          	$_POST['post_content'] = $_POST['post_content_accepted'];
        }else if(isset($_POST['post_content_rejected']) and !empty($_POST['post_content_rejected']) ) {
          	$_POST['post_content'] = $_POST['post_content_rejected'];
        }
    }
}

The above code will assign the selected post content (accepted or rejected) to the default post_content.

Can you please check and let me know if that works now.

#2628113

No, it isn't.
I don't understand, the code seems correct

#2628807

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've adjusted the code added to "Custom Code" section with code snippet "toolset-custom-code" as given under:
=> hidden link

add_action('cred_save_data', 'func_save_content_for_generic_field',10,2);
function func_save_content_for_generic_field($post_id, $form_data) {
    // if a specific form
    if ($form_data['id']==198) {
      
       if (isset($_POST['post_content_accepted']) and !empty($_POST['post_content_accepted']) ) {
          	$post_content = $_POST['post_content_accepted'];
        }else if(isset($_POST['post_content_rejected']) and !empty($_POST['post_content_rejected']) ) {
          	$post_content = $_POST['post_content_rejected'];
        }
      
      
            // add it to saved post meta
              $my_post = array(
                  'ID'           => $post_id,
                  'post_content' => $post_content
              );
  
            // Update the post into the database
              wp_update_post( $my_post );
        
    }
}

Can you please confirm it works as expected now.

#2628809

Yes, it works.

Now we have just the other issue

2) if I use [wpv-post-link item="@job-candidate.parent"] instead of [wpv-post-title item="@job-candidate.parent"] the the WYSIWYG field has not loaded and it doesn't work

It is strange that it doesn't work but it isn't fundamental

#2628811

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've adjusted the default value as given under in the form to display the parent post link:

[cred_show_group if="( $(post_title) eq 'accepted' )" mode="fade-slide"]
    [cred_generic_field type='wysiwyg' field='post_content_accepted']
      {
      "default":"Mx. [wpv-post-title] <br /> accepted for \"<a href='[wpv-post-url item="@job-candidate.parent"]'> [wpv-post-title item="@job-candidate.parent"]</a> \" <br /> ciao "
      }
    [/cred_generic_field]
[/cred_show_group]
 
  [cred_show_group if="( $(post_title) eq 'rejected' )" mode="fade-slide"]
    [cred_generic_field type='wysiwyg' field='post_content_rejected']
      {
      "default":"Mx. [wpv-post-title] <br /> rejectd for \"<a href='[wpv-post-url item="@job-candidate.parent"]'> [wpv-post-title item="@job-candidate.parent"]</a>\" <br /> ciao"
      }
    [/cred_generic_field]
  [/cred_show_group]

Can you please confirm it works as expected now.

#2628835

I think for the same alternative solution.
thanks, it works

#2628837

I think for the same alternative solution.
thanks, it works