I am trying to make a multi-step form here: hidden link
and have followed these threads:
https://toolset.com/forums/topic/multi-page-cred-form-or-save-button-for-long-form/#post-298832
https://toolset.com/forums/topic/multi-page-form-form-type-and-post-type-do-not-match/
So far this is what I've done:
1. I created a form for step one that creates a lesson (post). This is working
2. I created a second form for step 2 that edits content.
3. I created a content template and I selected "Don't assign to any post type" on it. Then I inserted the step 2 form in it.
4. In toolset > settings > custom code. I added this code snipet:
add_filter('cred_success_redirect', 'step2_redirect_func',10,3);
function step2_redirect_func($url, $post_id, $form_data)
{
if ($form_data['id']==1681)
{
$arr = array('content-template-id'=>1800); //the step 2 CRED form post ID
$url = add_query_arg($arr, $url);
}
return $url;
}
I have gotten my form to redirect to step 2 successfully but when it gets there the form is displaying error message: "Form type and post type do not match"
I'm guessing that while form 1 is creating the post correctly, step 2 form doesn't know what post it's supposed to be editing.
Can you help me? I've scoured the forums and can't figure out what I did wrong.
Thanks for help
Hi, can you tell me:
- What setting is selected for what to do after form submission in Form 1?
- What is 1800 - is that the content template ID containing Form 2, or the ID of Form 2?
- After submitting Form 1, what is the final URL you are redirected to on the front-end?
Q: What setting is selected for what to do after form submission in Form 1?
A: Go to page > New Lesson Step 2 (It's a page containing form 2 but it's not the containment template)
Q: What is 1800 - is that the content template ID containing Form 2, or the ID of Form 2?
A: This is the id of the content template containing form 2
Q: After submitting Form 1, what is the final URL you are redirected to on the front-end?
A: This is the url: hidden link
Okay I'm not sure how this is all working together, because this line looks wrong:
if ($form_data['id']==1681)
The ID here should be the ID of the first Form. I don't think the Form ID is 1681, I think the correct Form ID is 1679. I think the ID of the page containing the Form is 1681. So you should change 1681 to 1679.
Q: After submitting Form 1, what is the final URL you are redirected to on the front-end?
A: This is the url: hidden link;
Are you saying this is the URL you should be redirected to, but in actuality you are redirected to a different URL?I'm not sure how this URL redirect is happening, if the Form ID is 1679 and your code looks for 1681.
I apologize, You are right, I put the id 1679 of the form instead of the page over the weekend and that's how it's redirecting to: hidden link
Here is are screenshots of what my code looks like now and the form 1 redirect selections.
But still it's displaying the same error message, even after I put the id 1679.
If it helps try creating a new test lesson (post) and clicking next if you'd like: hidden link
If you would like I could give you access to the backend of the wordpress site if you want to take a closer look.
Thanks for your patience with me and for helping me through this issue.
Okay I see, thanks. Yes I think that it would be helpful for me to log in and see how everything is put together. If that's okay with you, please provide admin login credentials in the private reply fields here and I'll take a closer look. Thanks!
FYI - Forms shortcodes are documented here: https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/
Okay thanks, I understand a bit better now. I think you'll need to adjust the way the edit post Forms are inserted in each Page. For example, in the Page for step 2, I have removed the Form block and replaced it with a custom HTML block. I have included the step 2 Form using a cred_form shortcode. Then I added the post attribute to the shortcode and nested the wpv-search-term shortcode to set the value of that post attribute using a URL parameter new-post-id:
[cred_form form="1781" post="[wpv-search-term param='new-post-id']"]
Now the Form knows which post to edit because you will have that post ID in a URL parameter called "new-post-id". So now that we have set up the Form to receive the post ID attribute, we need to update the redirection script to add the new post ID into the redirect URL along with the content template ID. Basically just add that key/value pair into the $arr array like so:
// This will redirect you to step 2 after submitting step 1
add_filter('cred_success_redirect', 'step2_redirect_func',10,3);
function step2_redirect_func($url, $post_id, $form_data)
{
if ($form_data['id']==1679) // 1679 is the ID of the step 1 Form
{
$arr = array('content-template-id'=>1800, 'new-post-id'=>$post_id); // add the step 2 content template ID and the new post ID as URL parameters
$url = add_query_arg($arr, $url);
}
return $url;
}
I've made the changes up to this point so you can see how things will fit together. I also added the Form shortcode to the Lesson Step 3 page. I did not add the redirection API code yet for redirecting to step 3 after submitting step 2. That should be your next step. Let me know if you get stuck, and I can give some more direct guidance.
Ok, I inserted the code. Still not working. Sorry I don't know what else to do.
Ok, I inserted the code. Still not working. Sorry I don't know what else to do.
What code did you insert, and where did you insert it exactly? Please be specific so I know what you have done so far. I was looking in Toolset > Settings > Custom Code and I do not see any code for step 3. I see the code I already added for step 2, and it is working just as I described.
So sorry, for not being specific. I'm just so tired of this form and really appreciate you trying to help me.
You are saying that form 2 is working? I don't see it working on my end. I was trying to make sure that form 2 was working before I moved on to form 3.
Can you check if form 2 is working? Or is it me?
Sorry, I see what you mean. I was working with the Form in the Page directly, not using a Content Template parameter, so it was working in my tests but not in the normal workflow. Here's the URL you would end up at after the first Form:
hidden link
If you remove the Content Template ID URL parameter, it goes to the New Lesson Step 2 page and loads Form 2 successfully. You can see that at this URL:
hidden link
Since the Form is actually in the Page contents, there's no need to apply a different Content Template in the URL. So I've edited the redirection scripts to point to the correct URL for Form 2, without a Content Template ID. Now start step 1 here:
hidden link
You can submit Form 1 and see Form 2, then submit Form 2 and see your edits appear in wp-admin for the new post. After submitting Form 2, you'll end up at Form 3.
This is where you need to take over. Form 3 is set to create posts, but I think you want to change that to edit posts. Don't worry about making changes in the custom code snippet, I rewrote it and added all the Form IDs you've already created. Now each redirect will go to the correct page with the post ID added in a URL parameter.
After that be sure to update the Pages that hold Forms for Steps 4 - 6 . Use the shortcode in the Page for Step 3 as a guide. Change the numeric Form ID to display the correct Form.
Thank you!!!! Thank you!!! I know you practically had to spoon feed it to me but it worked. All my steps are working now that I switched over to inserting the form directly via shortcode into each step page instead of using a content template and the code that you inserted in settings covers all the steps. Thanks for all your help!
I finished all the steps now. Thanks!
You're quite welcome, that's what we're here for! This is pretty advanced stuff that isn't self-explanatory in any way, so kudos to you. Feel free to reach out anytime for guidance.