Skip Navigation

[Resolved] Post forms saved in progress / Paged forms

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

Problem: I would like to create a multi-step Form.

Solution: Create multiple Forms as described in the post: https://toolset.com/forums/topic/multi-page-cred-form-or-save-button-for-long-form

Update the custom code to work with the latest software versions:

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;
}

If your site uses Layouts, you should create an unassigned Template Layout instead of an unassigned Content Template. Then the code should include the layout ID, not the content template ID, and the proper URL parameter.

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('layout_id'=>12345); //the step 2 CRED form template ID
$url = add_query_arg($arr, $url);
}
return $url;
}

Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-editing/
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/building-forms-for-editing-when-using-layouts/

This support ticket is created 4 years, 10 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 16 replies, has 3 voices.

Last updated by hansooH 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1275121

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

#1275149

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.

#1275213

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

#1275215

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.

#1275219

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)

#1275223
Screen Shot 2019-06-23 at 3.14.54 PM.png

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
*/
#1275235
Skjermbilde 2019-06-23 kl. 21.37.49.png

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

#1275245

My issue is resolved now. Thank you Christian, great support!

Deactivated the redirect in form, and then the hook worked 😉

#1275247

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

#1275263

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.

#1275265

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;
}
#1275267

😉

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?

#1275269

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.

#1275271

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.

#1275273

Ok great, glad it's working for you.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.