Skip Navigation

[Resolved] Creating a Multi Page Form

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

Problem:

Setup multiple steps Toolset forms.

Solution:

It is a custom PHP codes issue, for example:

https://toolset.com/forums/topic/creating-a-multi-page-form/#post-1623885

Relevant Documentation:

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

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.

This topic contains 8 replies, has 2 voices.

Last updated by filipeC 2 months, 3 weeks ago.

Assigned support staff: Luo Yang.

Author
Posts
#1612383

I am trying to set up a multipage form that allows users to submit entries (custom posts).

I found the instructions here:
https://toolset.com/forums/topic/multi-page-cred-form-or-save-button-for-long-form/#post-298832
And this addendum:
https://toolset.com/forums/topic/post-forms-saved-in-progress-paged-forms/

So far I have:
(1) Made two forms, one for each form page (there will eventually be several pages), and set it to the recommended settings.
(2) Inserted the first form, the Create New Entry, into a blank page. This form works.
(3) Created a new Content Template, and inserted the second page form, Edit Section 1, into it
(4) Added a link on the Content Template for the custom post type for editing the section. The form works when accessed from here.
(5) Added the custom redirect code to Toolsets > Settings > Custom Code Snippets
- Replacing the form id with the form id of the first page entry: if ($form_data['id']==8265)
- Replaced the content template id with the id number from step 3: $arr = array('content-template-id'=>8272)

The problem seems to have come from the fact that when I first tried to set this up, I put the Edit Section 1 form into a blank page, before realizing that that doesn't work. I then deleted that page and created a Content Template, as is recommended. But the redirect is still trying to send me to the deleted page (the url I get redirected to is /edit_section_1_trashed/?cred_referrer_form_id=8195). How do I fix this?

Here's the full code snippet I used:
<?php
/**
* Send users to Edit Section 1 after successful submission of Create New Entry form
*/

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']==8265)
{
$arr = array('content-template-id'=>8272); //the step 2 CRED form template ID
$url = add_query_arg($arr, $url);
}
return $url;
}

Link to Create New Entry page: hidden link
Link to Edit Section 1 page: hidden link

#1612445

Actually the second page form, the Edit Section 1 form, isn't working correctly. I can access it by clicking on the link on the Edit Section 1 link in the custom post, but hitting submit doesn't do anything (doesn't save the data to the custom post type, doesn't return a visible error, and doesn't return to the post).

#1613405

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

It is a custom PHP codes issue, please provide a test site with the same problem, fill below private message box with login details and FTP access, also point out:
1) The forms URLs and content template URLs
2) Where I can edit your PHP codes,

I need a live website to test and debug, thanks

#1623875

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, I can login your website, will update here if there is anything found

#1623885

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

I have done below modifications in your website:
1) Edit the post form "Shipwreck (Create New Entry)":
hidden link
In section "Settings", option "After visitors submit this form" choose "Display the post"

2) As you can see above post form's ID is 8195, so I have changed the PHP codes from:
if ($form_data['id']==8265)

To:
if ($form_data['id']==8195)

Please test again, check if it is fixed.

More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
form_id. The form ID.

#1624625

It works now. However, I tried repeating the steps to create the third page of the form. I copied and pasted the code snippet exactly, changing only the description, form ID and content template ID, but activating this new code snippet produces a critical error.

#1624737

I'm also having trouble editing content templates because even though they work, the shortcodes are not visible, so I can't see what I'm working on (the screenshot from below is from the Shipwreck page template. The areas circled in red have shortcodes, added using the Toolset Fields and Text block, but I can't tell that there's anything there unless I look at the live page.

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/im-also-having-trouble-editing-content-templates/

#1625043

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Q1) but activating this new code snippet produces a critical error.
Please check these:
Dashboard-> Toolset-> Settings-> Custom code
There are two items: edit-shipwreck-pg2 and edit-shipwreck-pg3
Both of them are using same PHP function name: stegvis_skjema_el_test
This will conduct the PHP error.

And in your case, it needs only one custom PHP codes, I have edited the first item "edit-shipwreck-pg2", add below codes in line 18~22:

if ($form_data['id']==8265) // step 2 form ID
{
$arr = array('content-template-id'=>8894); //the step 3 CRED form template ID
$url = add_query_arg($arr, $url);
}

Please test again, check if it is fixed.

According to our support policy, we prefer one question one ticket, for other new questions, please check the new thread here:
https://toolset.com/forums/topic/im-also-having-trouble-editing-content-templates/

#1625821

I understand now. That fixed it. Thanks so much! I'll check the other thread for the other problem.