Skip Navigation

[Resolved] Want the contents of 2+ forms to go into one CPT

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

Problem: I would like to allow Users to create a post using Forms, but only fill out part of the post information in the first form. In subsequent forms, users should have the ability to add more information in a stepped approach.

Solution: Use one New Post Form and two Edit Post Forms to achieve this stepped approach with partial form captures. Use expert form builder mode to delete required fields from each form as needed.

This support ticket is created 4 years, 5 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 6 replies, has 2 voices.

Last updated by ianB-9 4 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#2006735

I require some help with a client project I have that does not seem to be covered by your online documentation. While the scenario-based information is very helpful when working with standard types of websites (e.g. membership sites), it is lacking somewhat when looking for some specific information! I think what I'm creating is not very exotic or difficult - but it does venture a bit beyond a standard format.

I am creating what is effectively both a membership site and a listing site - a website through which tutors can enroll and be listed so that prospective students can find them.

I have created a CPT "Tutors" and hope to place all of the required information within each CPT, recording the basic information about the tutor (name, photo, rates they charge, etc.), as well as what specific courses or areas of knowledge they are able to teach. Because this latter aspect can be very broad, I have divided it up into two age-based timeframes: school and college/university.

What this means is that, once the tutor has registered on the website (your tools are doing a very good job of this function!), their next step is to fill out a form (Form A) and submit their personal information. Once that information has been looked over by a human being and the tutor's application accepted, they can then go onto the website and complete and submit one or two course questionnaires: one regarding school courses (Form B) and the other for university courses (Form C).

All of the data from all three forms is supposed to end up in the Tutors CPT and I have created corresponding fields in the CPT to take them. When Form A is submitted, all the data makes its way into the CPT as expected; it is fundamentally creating a new record in the CPT. However, when Form B or C data are submitted, a new CPT record is created for each! In other words, when a logged-in tutor has returned to the website after successfully submitting Form A and they complete and submit a Form B or a Form C, the data don't end up appended in their tutor record like I desire, they end up in a new record.

In summary, please tell me how I can have one CPT with many dozens of fields in it and have the data from three separately submitted forms all end up in in one CPT record.

I hope I'm making myself clear here and that there's a relatively simple way to make this happen as desired!

#2006813

Hello, it sounds like you have 3 Forms that are all configured to create new posts in this CPT, is that correct? Forms B and C should be configured to edit an existing post instead of creating a new post. Then each of the 3 steps can be performed on the same post, rather than creating a new post for each step.

Let's say your CPT has 30 fields. In Form A that creates new posts, you can include fields 1-10 and delete fields 11-30. Then in Form B that edits an existing post, you can delete fields 1-10 and 21-30 from the Form builder, to include fields 11-20 only. And in Form C, you can delete fields 1-20 to include only fields 21-30 in the Form builder.

The lesson for editing a post with Forms is here: https://toolset.com/course-lesson/front-end-forms-for-editing-content/

Will this workflow work in your case?

#2006893

Thank you for your reasonably quick and informed response. It was above my expectations!

You have totally understood me and the workflow you've suggested will work for me. I have done what you've indicated, which is basically to configure Form B to edit an existing post. I have done that but now get the error message "Form type and post type do not match" when I try to view the form on the front end website while in the role of Tutor. The possible reason for this requires me to give you a bit more information:

When a user completes and submits Form A, they are in the role of "Pending Tutor." I have done this to, effectively, lock them out of being able to even view Form B; they need to be approved to be a user of the site and an admin person changes their role from Pending Tutor to Tutor. In other words, when they complete Form A they're a Pending Tutor and when they do likewise with Form B they're a Tutor. Could this be the root cause of this error?

If this is, then a workaround is going to be required. In simple terms, I can't let anyone who's completed and submitted Form A be allowed to even see Form B until an admin person approves their application (Form A). My workflow was to have their role simply changed from Pending Tutor to Tutor to accommodate this.

By the way, searching on the error message term "form type and post type do not match" gets me nowhere in your online docs.

While I have your attention, there's something else I can't figure out. Please look at this screenshot: hidden link It's of what we've been referring to as Form B. The forms are very simple and experimental at the moment. Those first two fields you see on the screenshot - legal first and last name - are actually from Form A and the lock icons on them fundamentally mean they can't be erased from the form! They're being "carried over" into Form B, presumably because they exist in the related CPT. When I currently view the pseudo Form B in the block editor, those two fields are there also. How do I get rid of them?

#2006911

I've tried to edit the paragraph that begins "If so, I believe..." -- but the editor doesn't seem to want to accept my input! In short, ignore this paragraph because I need to change the role of the user between their completion of Form A and Form B because that's the only way I know to stop them from even seeing Form B until an admin has approved their application. A workaround might be required.

#2007583

I have done that but now get the error message "Form type and post type do not match" when I try to view the form on the front end website while in the role of Tutor.
I don't think this is related to the User role. Usually this message happens when the editing Form is confused about which post should be edited. Can you explain where you placed the Edit Form on the site, and how you are directing the User to that Edit Form? Normally an Edit Post Form is placed in a blank unassigned Content Template, then you insert a link to that Edit Post Form in the original post template or in a View of posts somewhere.

I'll be glad to take a closer look if you provide login credentials here in the private reply fields. I'll need an admin login to see how the Form is configured and placed in wp-admin, and I'll need one of the User logins as well to test the Form on the front-end of the site.

Those first two fields you see on the screenshot - legal first and last name - are actually from Form A and the lock icons on them fundamentally mean they can't be erased from the form! They're being "carried over" into Form B, presumably because they exist in the related CPT. When I currently view the pseudo Form B in the block editor, those two fields are there also. How do I get rid of them?
Okay yes, required fields will show up as being "locked" in the drag-and-drop editor. The only way to remove them in this case is to turn on "Expert Mode" in the Form builder. This will expose all the shortcodes used to generate the Form contents. You can find the fields in that content by examining the shortcode field slugs and labels associated with each field, and delete the fields manually.

#2007811
Screen Shot 2021-04-01 at 4.14.43 PM.png

Okay it looks like the Edit Post Form was originally placed directly in the Page contents here: hidden link
However, that placement did not give the Form any context of which Tutor post it should edit. The Form thinks you're trying to edit whatever post it's displayed on...in this case it was the Page itself, which isn't going to work because the Form is designed to edit Tutor posts. That's why you see the post type and form do not match error message - can't edit a Page with a Tutor Form.

There are a couple of ways to set the post context dynamically, so that the Form will work for all Users and all their Tutor posts. The first option is to add a View of Tutors to the Page where you want to show the Edit Post Form, and place the Edit Post Form inside the loop of that View. The Form will be displayed once for every Tutor post in the results, and the context will be inferred from the loop of the View. That is the approach I took here, even though there is only one Tutor post. I created a View of Tutor posts, filtered by post author, where the post author is the same as the current logged-in User. I placed a limit of 1 result in the View, and ordered it by post date descending order, so the View will loop over the one Tutor post that the current logged-in User created most recently. Usually you would use a View like this to display a list that includes the post title or post link, maybe the featured image, or other post information. In this case, we're displaying an Edit Post Form in the loop instead. Screenshot attached here showing how the View's filter is configured, and you can read more about filtering Views here: https://toolset.com/course-lesson/creating-a-view/#filter-the-list-of-posts

Now when logged in as the tutorone User I can see the Edit Post Form appear on the page here, editing the Tutor post "Tutor One", created by the tutorone User: hidden link

If another User logs in they will see their own Tutor post here, or a message saying "No results found".

If you don't want to place the Edit Post Form in a View, the other solution to the "post type and form do not match" problem is to place the Edit Post Form in an unassigned Content Template, and then create an Edit Post Link inside the View of Tutors, or inside the Tutor template, as explained in the documentation I mentioned earlier: https://toolset.com/course-lesson/front-end-forms-for-editing-content/

For the next step, you'll need to create a second Edit Post Form that includes the third group of fields, and another Page to hold that Edit Post Form. You can review the School Courses and Prep Exams page to examine the View of Tutors I created, and see how the Form block is placed inside the loop of that View. You'll create a similar View to display the second Edit Post Form in another Page, or you can use the Content Template approach I mentioned to display an edit post link in the Tutor post template or a View of Tutors.

Hope this helps clarify things. Let me know if you get stuck on the next step and I can jump in again and give you more advice.

#2012485

My issue is resolved now. Thank you!