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?
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/
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 );
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.
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.
My issue is resolved now. Thank you!