Hi,
I am trying to make "progressive forms". Forms saving steps.
I am using this support tread:
https://toolset.com/forums/topic/multi-page-cred-form-or-save-button-for-long-form/
1: But where should I put the "use the CRED API filter hook: "cred_success_redirect"?
2: And where do I put the code: "add_filter('cred_success_redirect', 'step2_redirect_func',10,3);
function step2_redirect_func($url, $post_id, $form_data)
{
if ($form_data['id']==4)
{
$arr = array('cred-edit-form'=>8); //the step 2 CRED form post ID
$url = add_query_arg($arr, $url);
}
return $url;
}"
3: And how do I find the correct form id?
****
Step 1: hidden link
Step 2: hidden link
1: But where should I put the "use the CRED API filter hook: "cred_success_redirect"?
See #2.
2: And where do I put the code: "add_filter('cred_success_redirect', 'step2_redirect_func',10,3);
If you are using a child theme, you can add this code to your child theme's functions.php file. If not, you can go to Toolset > Settings > Custom Code, create a new snippet, and add the code to the end of the snippet. Set the snippet to run everywhere.
3: And how do I find the correct form id?
Go to Toolset > Post Forms to see a list of all Forms. The numeric ID of each Form is shown next to the Form name.
Hi Christian,
Almost there (I think), but I get this error:
There was error when trying to re-run the snippet:syntax error, unexpected 'add_filter' (T_STRING) in /home/systeyay/public_html/wp-content/toolset-customizations/stegvis_skjema_el_test.php on line 11 A problem occurred when executing snippet "stegvis_skjema_el_test". The result of include_once is: ""
NB: This is a multisite, and for now I have put the code in the Toolset custom code area.
During testing I changed this line:
step2_redirect_func to my custom code label: stegvis_skjema_el_test (I tested first not doing that, so I thought it was worth a try. But so far, no luck.
Are you able to see where I lost track?
Step 1 page: hidden link
Step 2 page: hidden link
So if you changed the name of the function in one place, you should change it in both places:
add_filter('cred_success_redirect', 'stegvis_skjema_el_test',10,3);
function stegvis_skjema_el_test($url, $post_id, $form_data)
{
if ($form_data['id']==4)
{
$arr = array('cred-edit-form'=>8); //the step 2 CRED form post ID
$url = add_query_arg($arr, $url);
}
return $url;
}
This code should be added at the bottom of the snippet. If it's not working as expected, I'll have to log in and take a closer look. Please provide login credentials in the private reply fields here.
I am not using view in this matter, the forms are shortcoded into pages. Maybe this is causing problems?
Step 1 form: EL - Registreringsskjema V4 - Steg 1 (ID: 874)
Step 2 form: EL - Registreringsskjema V4 - Steg 2 (ID: 881)
You are seeing an error because you can't place plain text in a code snippet without using comments. The text "cred_success_redirect" should be removed as shown here in the screenshot, or commented out.
// this is a one line comment
/*
this is a multiple
line comment
*/
Hi Christian,
I am so sorry, but unfortunately it still don´t work.
No error warning in the script now:
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_filter('cred_success_redirect', 'stegvis_skjema_el_test',10,3);
function stegvis_skjema_el_test($url, $post_id, $form_data)
{
if ($form_data['id']==874)
{
$arr = array('cred-edit-form'=>881); //the step 2 CRED form post ID
$url = add_query_arg($arr, $url);
}
return $url;
}
And the first form redirects to the correct page (This is set in the after post sucess in form) (File attached),
but still I get this error on the second page, with the second form: Form type and post type do not match
My issue is resolved now. Thank you Christian, great support!
Deactivated the redirect in form, and then the hook worked 😉
The second step Form is an "Edit Post" Form. However, the Form has no way of knowing which post should be edited, because it is placed on a custom page. You have two options here:
1. Create a View that shows only the post you want to edit, and place the Edit Post Form in the View.
2. Create a Content Template that holds the Edit Post Form. In step 1, redirect to the new post with the Content Template applied as a URL parameter: hidden link
Hi Christian,
Thank you for sticking around! 😉 Thouht I had this solved.
I have now made a Content Template, but from there I am now totally lost. Unfortunately I have no idea how to continue from here. May I ask for some hands on support in this matter. This is only a dev site (Trying to learn toolset amongst other).
I would very much appreciate if you could get me a step further in this matter.
You need to update the redirect code snippet to redirect to the post URL with the content template ID added:
add_filter('cred_success_redirect', 'stegvis_skjema_el_test',10,3);
function stegvis_skjema_el_test($url, $post_id, $form_data)
{
if ($form_data['id']==874)
{
$arr = array('content-template-id'=>925); //the step 2 CRED form template ID
$url = add_query_arg($arr, $url);
}
return $url;
}
😉
Damn, this gets me confused 😉
1: Where do I find the Content template ID?
2: Must the Content template be conected to a page, or does it have to be a post?
3: The code supplied from you, does it have the correct content template id, or do I have to change the code in any way?
1: Where do I find the Content template ID?
Go to Toolset > Content Templates to see a list of all Content Templates. The ID of each template is listed here.
2: Must the Content template be conected to a page, or does it have to be a post?
It should not be connected to any post or page. It should be unassigned, as yours is now.
3: The code supplied from you, does it have the correct content template id, or do I have to change the code in any way?
It already has the correct template ID. You should use the code exactly as it is written.
HEY!
Now it seems to play. Had to set form 1 to display current post 😉
...but now the second form dont publish. The submit button (Lagre) dont trigger submit.
Ok great, glad it's working for you.