Skip Navigation

[Resolved] Link two forms

This thread is resolved. Here is a description of the problem and solution.

Problem:

Translate the new post with Toolset forms API hooks.

I have two forms created one for English and one for Spanish. And I need to be able to link them together.

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/link-two-forms/#post-1890445

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

https://wpml.org/wpml-hook/wpml_make_post_duplicates/

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by avansisI-2 3 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1889751

I have two forms created one for English and one for Spanish. And I need to be able to link them together.

My idea is that the user fills in an English form, and in his user area on the front-end he can fill in the translation using the Spanish form, for this he would need to be able to make that second form be linked to the first form.

I don't know if this is the most logical way to do this. you could help me?

#1890445

Hello,

I assume you are using WPML to translate the posts.

It needs custom codes, for example:
After user submits the post form for creating new English post:
1) Use action hook "cred_save_data", to trigger a PHP function, in this PHP function, duplicate the English post to Spanish post verson:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://wpml.org/wpml-hook/wpml_make_post_duplicates/

2) Use filter hook "cred_success_redirect", to trigger another PHP function, in this PHP function, get the Spanish translation post ID, and display another post form for editing the specific Spanish post:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
https://wpml.org/wpml-hook/wpml_object_id/
https://toolset.com/course-lesson/front-end-forms-for-editing-content/

#1894121

Okay,
I dont know how i can apply this code.
I try with a custom code, but i think that not worked.

The code:
368 is the id of spanish form
1642 is the id of english form

function quick_duplicate_save_data_action( $post_id, $form_data ){
$forms = array( 368 , 1624 );
if ( in_array($form_data['id'],$forms) ){
global $sitepress;
do_action( 'wpml_make_post_duplicates', $post_id);
}
}
add_action( 'cred_save_data', 'quick_duplicate_save_data_action', 10, 2 );

#1894497

As you know, we don't provide custom codes support.

If you need more assistance for it, please provide a test site with the same problem, also point out the problem form URLs and page URLs, I can setup a demo for you.

#1895979

I have setup a demo in your website:
1) Edit the custom PHP codes as below:
hidden link

function quick_duplicate_save_data_action( $post_id, $form_data ){
$forms = array( 368 , 1624 );
if ( in_array($form_data['id'],$forms) ){
    //global $sitepress;
    do_action( 'wpml_make_post_duplicates', $post_id);
  }
}
add_action( 'cred_save_data', 'quick_duplicate_save_data_action', 10, 2 );

add_filter('cred_success_redirect', 'custom_redirect',999,3);
function custom_redirect($url, $post_id, $form_data)
{
  $forms = array( 368 );
  $res = $url;
  if ( $form_data['id'] == 368  ){
    $es_post_id = apply_filters( 'wpml_object_id', $post_id, 'empresa', FALSE, 'es' ); 
    $es_post_url = get_the_permalink($es_post_id);
    $es_post_url = apply_filters( 'wpml_permalink',  $es_post_url, 'es' ); 
    $res = add_query_arg( array(
        'content-template-id' => '1708',
      'preview'=> 'true',
    ),  $es_post_url ); 
  }
  return $res;
}

2) Test the English form in front-end:
hidden link

After submit the form, it redirect me to the Spanish edit post form.

This is only a demo for your reference, you will need to customize it to what you want.

#1901025

My issue is resolved now. Thank you!