Sauter la navigation

[Résolu] How to setup a front end form with a parent and two child posts

This support ticket is created Il y a 6 années et 1 mois. 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)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Christian Cox Il y a 6 années et 1 mois.

Assisté par: Christian Cox.

Auteur
Publications
#1142302

Hi I am trying to set up a frontend form with forms. There is a parent "classification" to a child (customer) which in turn is a parent to "Contact persons" child. The parent is Customers and the children are classification and contact persons. In both Instances, it is a one to many relationships. Ie "Classification" 1 to ∞ "customers" 1 to ∞ "contact persons"

The relationships have already been established. In short, I am trying to replicate the "add new customer" screen in a front-end form. This is the first time since this feature has been implemented that I am trying to do this and I am a bit lost. Have not been able to find documentation to assist me with this.

#1142519

Hi, the basic idea here is you will set up two Forms - one to create Customers, and another to create Contact Persons. One Form can only edit or create a single post, so you can't create Customers and Contact Persons in the same Form.
1. Create a New Customer Post Form. Use the auto-generate button to generate the Form contents. A Classification select field will be automatically included if you have a post relationship set up.
2. Insert this Form on your site, and Users can begin creating Customers and relating those new Customers to some Classification.
3. Create a New Contact Person Post Form. Use the auto-generate feature again to generate the Form contents.
4. Insert this Form on your site, and Users can begin creating Contact Person posts and relating those new Contact Persons to some Customer.

Note that Users will select one parent post in each Form. There is no "grandparent" post selection feature. If you want to preselect a parent post, you can use shortcode attributes or URL parameters. I can help with that if you'd like.

#1142900

Hi Christian, Thx for this!

Ok, I have made a " add new customer" and "add new customer contact" forms. everything is now working as expected. I understand the concept of the passing through of URL parameters, however, the problem is in the execution of same. If you could guide me through that, please.

#1143198

Okay start on the Classification post. Add a text link to a Page containing the New Customer Form. Add a URL parameter at the end of the link like this:

<a href="<em><u>lien caché</u></em>">Add a Customer to [wpv-post-title]</a>

This will pass the current Classification ID along to the New Customer Form. In the New Customer Form contents, find the Classification parent post field and add "cid" as a urlparam attribute. Wrap the parent post field in a div hidden with CSS, and the parent select field won't be visible to the site Users. Like this:

<div style="display:none;">
[cred_field field="@your-relationship-slug.parent" class="form-control" output="bootstrap" select_text="--- not set ---" urlparam="cid"]
</div>

Note that mine is just an example, your field will be different depending on your post relationships and other configurations. The important part is the urlparam attribute, which must match the URL parameter you added to the link.

Once you have that working, repeat the process starting on the Customer post. Add a link to the New Contact Person Form, add a URL parameter at the end of the link, and add the urlparam attribute to the parent post field in the Form.

More information about the cred_field shortcode here:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field