Skip Navigation

[Resolved] Creating a new Parent when creating a child post

This support ticket is created 5 years, 6 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)

Author
Posts
#1289839

Tell us what you are trying to do?
I'm trying to create a new parent post when creating a child post. Because of the structure of the site, the parent is required to categorize everything correctly.

I have created a limited form to create the parent and implemented it above the form to create the child. With Ajax, the Parent does show up in the select for the Parent Company after the Add Company form is submitted. However, from a usability standpoint, this is a little awkward. Possibly a popup would work better.

Is there a way, that I've missed to more elegantly integrate the Adding of the parent in the same form as adding the Child? Similar to how the Add a new taxonomy is integrated if that is included?

Is there any documentation that you are following?
I've been following this, but it does not discuss the case of creating a Parent that does not exist.

Is there a similar example that we can see?
Thre is no example I could find of integrating the creation of both the Parent and Child, but the adding of a Taxonomy is the closest to what I was expecting.

What is the link to your site?
hidden link

You will need a login to see the form. I can provide if necessary

#1289905

Hi, no there's really nothing you've missed here. In general, a Form edits or creates one post or one User. It is not possible to create more than one post or edit more than one post in a single Form without custom code. One way to enforce this workflow is to only allow Users to create child posts by following a create child post link from the parent post. It's still not as streamlined as being able to create both in the same Form, but it does require one to create a parent first so it's available in the child Form. Let me know if you have questions about that.

#1289935

OK, but it seems like a standard use case? One more question. Is there a way to display a form as a pop up within Toolset? For example to just provide a click to open the add parent form, if the parent does not exist?

#1289967

Toolset doesn't provide a modal interface element per se, but it is possible to load the Bootstrap library (Toolset > Settings > General). The Bootstrap library includes a modal element you could implement with some custom code: https://getbootstrap.com/docs/3.3/javascript/#modals

As long as the form shortcode exists in the page when the page loads, and you don't move it around in the DOM, it should be okay in the modal markup.

#1289987

I tried this, but the shortcode displays as text and not as a form.

#1289989

May I see how you have it implemented? Is this content loaded with AJAX, or is it present on page load?

#1290021

I'm sure it's incorrect, but I'm not sure why the shortcode wouldn't show the form I tried but the code below and the code with just the brackets, neither worked. Here the code for the form. This may be just beyond my skillset, but I wish I make it a little more usable that the current set up.

[toolset_access role = "Guest" operator = "deny"]

[credform]
<!-- The modal -->
<div class="modal" id="addcompany" tabindex="-1" role="dialog" aria-labelledby="modalLabelLarge" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Add Conpany</h4>
</div>
<div class="modal-body">
<p>{!{cred_form form='add-company'}!}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

</div>
</div>

</div>
</div>
[cred_field field="form_messages" class="alert alert-warning"]
<div class="form-group">
<label>Company</label> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#addcompany">
Add
</button>
[cred_field field='@company-equality-report.parent' class='form-control' output='bootstrap' select_text='--Select a Company--']
</div>
<div class="form-group">
<label>Equality Report Title</label>
[cred_field field="post_title" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Department</label>
[cred_field field="department" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Who was involved?</label>
[cred_field field="who-was-involved" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Type of Issue</label>
[cred_field field="type-of-issue" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Date of Incident</label>
[cred_field field="date-of-incident" force_type="field" class="form-control" output="bootstrap"]
</div>
<div class="form-group">
<label>Short description</label>
[cred_field field="short-description" force_type="field" class="form-control" output="bootstrap"]
</div>
[cred_field field="form_submit" output="bootstrap" value="Submit" class="btn btn-primary btn-lg"]
[/credform]
[/toolset_access]
[toolset_access role = "Guest" operator = "allow"]
Oops! You must be logged in to view this page. Please hidden link">Register or  to your account.
[/toolset_access]

#1290023

The main problem I see here is you have placed one Form inside another. That's not going to work, because HTML doesn't allow nested forms like this. You'll have to move the nested cred_form shortcode outside of the first form's contents, and into the main template.

#1290029

Ok, I was hoping the modal might be a way around the nested forms issue. If I place it outside the form, then it's no longer next to the field it is supporting. I do think it would be a nice feature that allows you to add a field from a parent, to have the capacity to add a new parent if necessary. Or to allow a modal or pop up type form that can have fields from the parent. I can execute what I want, but it would be nice to have options to design a workflow that makes some more sense.

Thank you for your assistance!

#1290043

If I place it outside the form, then it's no longer next to the field it is supporting
From a functionality perspective, you can place the modal markup code anywhere. It doesn't have to be in the Form. The addcompany button to trigger the modal can stay in the Form, and still open the modal successfully.

I encourage you to submit your request for improving the workflow of creating related posts in our suggestion form over here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
This form submits to key stakeholders who decide which features to implement in upcoming releases.

#1290057

My issue is resolved now. Thank you!