Skip Navigation

[Resolved] Same form to multiple post types

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

Problem:

The user had three custom post types (cpt1, cpt2, cpt3) and a custom field group called "cf" assigned to each of them. They wanted to use the same form for all custom post types to submit data from the frontend. However, Toolset only allows a separate form for each custom post type.

Solution:

-Create separate forms for each custom post type (cpt1, cpt2, cpt3).

- Go to Toolset > Content Templates and create a new Content Template, without assigning it to any post type (e.g., name it "conditional-logic").
- In the Content Template, use Conditional Blocks and Forms Blocks to create the desired conditions for each custom post type. For example:

[wpv-conditional if="( '[wpv-post-type]' eq 'cpt1' )"]
  [shortcode for the form for cpt1]
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-type]' eq 'cpt2' )"]
  [shortcode for the form for cpt2]
[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-type]' eq 'cpt3
[/wpv-conditional]

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 11 replies, has 2 voices.

Last updated by fahimS-2 1 year, 10 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2570181

Tell us what you are trying to do?
I have 3 custom post types cpt1, cpt2, cpt3. I have a custom field called cf which I assigned to all of the custom post types. I have created a form to get the custom field data and assigned it to cpt1. Now I want to assign the same form to cpt2 and cpt3. How can I do that?

#2571425

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

The post forms in Toolset are for each post type.

So for your scenario, you need to create a post form called C1 Add and another form C1 Edit to add and edit C1 post types.

For the C2 you need to add a C2 post for for edit and C2 post form for Adding. And the same for the C3.

On all three forms you will add the CF as an input in the form.

If the C1 form is submitted, the CF inside the c1 will get a value. If C2 is submitted the Cnside C2 will get a value nd so on...

For more information:

https://toolset.com/course-lesson/front-end-forms-for-adding-content/

Thanks.

#2571433

I want to use the same form to all of the custom post types. That is my problem. Is there any solution?

#2571819

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Unfortunately, it is not possible to do so. The problem from the Toolset point of view is that if you have one form, Toolset does not know which custom post type the form is about to add the custom field there.

Would you please give me the scenario that you have to have three different custom posts ut one form? I might be able to find an alternative solution to avoid such a thing.

Thanks.

#2571835

Yes, I have 3 different custom post types which have the same custom field group. I have a post edit form that will take input of a custom field of the custom field group. I have a elementor template to show all of the 3 post types and I added the post edit form in the template. Now the form is visible on the frontend for only one post type that I assigned. The other 2 post types aren't showing the form in the frontend rather showing 'Form type and post type do not match'. Kindly help.

#2572545

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Ok there is no escape for the forms. You need to create three forms for the three post types.

You will get a shortcode for each form.

Now inside the Elementor template you can use this shortcode:

[wpv-conditional if="( '[wpv-post-type]' eq 'custom-post-slug-1' )"]
  shortcode for the form for custom-post-slug-1
[/wpv-conditional]

Replace "custom-post-slug-1" with the slug of your custom post 1.
Inside the shortcode, instead of:

shortcode for the form for custom-post-slug-1

Add the shortcode for the form that you have created for the custom post 1.

Duplicate the same code for the other two post types. Now system will detect which post type is in question and the form for that post type will show.

#2573557

I used this shortcode:
[wpv-conditional if="( '[wpv-post-type]' eq 'saas' )"]
[cred_form form='form-for-saases']
[/wpv-conditional]

But it isn't working. Can you kindly check?

#2573629

Christopher Amirian
Supporter

Languages: English (English )

I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.

Make sure you set the next reply as private.

Also give me the URLs of the Elementor Template so I can check the code.

Thanks

#2574321

Christopher Amirian
Supporter

Languages: English (English )

Screenshot 2023-03-16 at 17.57.31.png

Hi there,

I found a solution doing the steps below:

- Go to Toolset > Content Templates
- Add a new Content Template and do not assign it anywhere. (I named it conditional-logic)
- Use the Conditional Block and The forms block to create the condition you want.
- Check the attached screenshot to see how I added the logic.
- In the Elementor layout added an HTML element and used the code below:

[wpv-post-body view_template="conditional-logic"]

- This code retrieves the content template in question.

Now please go to the content template and add other conditionals for the other post types and it should work.

At the end you always should see one form out of three forms you have created.

Thanks.

#2574601
Screenshot_7.jpg

Thanks for the assistance. The method is working.

While editing the elementor template the word 'Rating' is appearing two times. Though it doesn't appear on the front end. Even when I add a shortcode of form in the shortcode element in elementor, the word 'Rating' appears two times.

Is there any way to remove the extra 'Rating' word?

#2576139

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I checked and not sure why that happens. But as this is not affecting the front end of the website you can ignore it.

Thanks.

#2579019

My issue is resolved now. Thank you!