Skip Navigation

[Closed] adding selector for second parent in form

This support ticket is created 3 years, 10 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 17 replies, has 2 voices.

Last updated by Jamal 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1659565

Tell us what you are trying to do?

I have created a form to create a child post, with one parent pre-selected. The child post-type is configured with two different parent post-types.

The relationship between the the child and first parent post-type is one to many... each parent can have many children but each child can only have one parent (of this post type).. I have successfully pre-populated this field as the child post is created from within the first parent post.

The second relationship is many to many with each child post potentially having many of the parents of the second post type. and each of the second parent post type may have many children.

To help in understanding... the first parent is "company-profile" the child is "funding event" and the second parent is "funder".

I am trying to add the ability to select multiple parents of the second post-type but can't figure out how to do this. The "Add fields" button in the form builder only provides the ability to add one type of parent post-type (the type i have already pre-selected) not the second parent post-type. I tried adding the second parent post type by inserting the first one again and editing the code as follows:

[cred_field field='@funder_funding-event.parent' class='form-control' output='bootstrap' select_text='--- not set ---Funder no.1']

but when I open the form I get the error message: There is a problem with @funder_funding-event.parent field. Please check CRED form.

I am after the ability to add more than one funder.. with the option for one showing initially and when that is completed the user should be asked if they want to enter "Another funder?" and the box should be autocomplete rather than a dropdown as we already have over 700 funders.

Is there any documentation that you are following?
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1661101

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

From what I understand so far, you are trying to implement two features that are not yet supported by Toolset:
- Connect posts in two relationships on the same form.
- Connect multiple posts in a many-to-many relationship on the same form.

Currently, none, of the above is possible with Toolset forms:
- A relationship form can only act on one relationship.
- A Many-to-many relationship form can only connect one parent in a time.

I do think that what you intend to have is possible with multiple forms or with custom coding:
- You can create two forms for the two relationships and configure one of them to redirect to the other one. Basically, creating a wizard(step-by-step form) from multiple forms.
- Custom code that will build the second relationship field, and custom code that will connect the posts. This is actually out of the scope of this support forum. You may want to hire one of our partners to help with that. https://toolset.com/contractors/

For the first case, just configure the first form to redirect to a page or content template that has the second form and pass the child post arguments through URL parameters and generic fields, check the following documentation articles:
- https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/
- https://toolset.com/documentation/user-guides/front-end-forms/inserting-generic-fields-into-forms/
- https://toolset.com/course-lesson/adding-generic-fields-to-forms/

For the second case, check our forms API here, and the WordPress shortcode API, as you will most probably add the fields with a shortcode:
- https://toolset.com/documentation/programmer-reference/cred-api/
- https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/
- https://codex.wordpress.org/Shortcode_API

I hope this helps. Let me know your feedback.

#1663797

Jamal

Thanks for your response... I will try with the two stage form.

I followed https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

I am a bit lost as to how the second form to create the second relationship is attached to the first. I can pre-populate the parent id in a child post but here I just cant figure it out.

I have created the form to create the child post type and the second form to select the second parent. I have tried to connect the two but can't figure out how to pass the child post arguments through.

I tried following the instructions at: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/?utm_source=credplugin&utm_campaign=cred-relationship-forms&utm_medium=help-link-plugin-row&utm_term=CRED But I couldn't get it to work

I have set up the first form so that when it is completed the user is taken to a new page containing the second form once the first is submitted... but the form isn't linked. I have also tried adding a link to the form but got the error "The item to connect items to can not be connected with this relationship"

Can you please help.... how do I connect the first and second forms so that the second form will know what child post the second parent post type relates to.

Thanks

Peter

#1664935

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Peter,

From what I can see, the page that holds the second form does not have a way to know which post we are editing. What I suggest is:
1. Configure the "Create Form" to redirect to the post page, check this screenshot hidden link
2. Create a content template to display the custom post type and inside of it, create a condition to display the second edit form if no relationship is already present.

Or you can:
1. Configure the "Create Form" to redirect to a page.
2. Create a view inside the page that will query the custom post type and get the created post, which can be tricky, or requires some custom coding(get the last post created by the current logged in user with the given status).
3. Use the second "edit form" inside the loop of the view. You will have as many forms as many posts returned by the view.

I hope this makes sense, let me know if you have any doubts/questions.

#1667969

Thanks Jamal

I have tried the first option suggested (always avoiding custom code) and it is coming together. I need to build a multi-layered condition that I need to work through but I have the basic connection working.

two questions for now about the relationship form.

1. I wonder if it is possible to have the auto search without displaying the dropdown... I don't want users to see all of the parents available for selection.

2. I am wanting to give the user the option to add another parent that is not on the list of choices... preferably a new post with just a title. how would I go about that in the form?

Thanks again

#1668549

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Peter, I am glad I could be of help 🙂

However, for support rules, we are able to handle only one issue at the time. This helps us to bring you a better service and also helps other users to find all the information here exposed.
For that reason, I'll try to answer your questions here, but if you need further assistance with any of them, please create a new ticket and you can assign it directly to me. In that way, you don't have to wait and we can continue working on it.

1. You can use the argument "use_select2" of the cred_field shortcode, this will generate a searchable list instead of a dropdown. Check the shortcode arguments here https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field

2. This will need custom code because each form on Toolset only creates or edits one post. We can't create a post and edit another post on the same form without custom coding.
The easiest way, I can think of, is using generic fields. You can insert a generic field that will hold the title of the additional parent, then you can hook into the cred_save_data for the form and programmatically create the new parent, then assign it using relationship API. Check the following articles:
- Generic fields: https://toolset.com/course-lesson/adding-generic-fields-to-forms/
- cred_save_data hook: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- Create a new post: https://developer.wordpress.org/reference/functions/wp_insert_post/
- Connect these 2 posts: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

All the best,
Jamal

#1672107

Jamal

I have made some progress and have added a relationships form to the child post content template. I had a bundle of other issues but have been working through them.

I have a number of issues I hope you can help with.

1. the user should be presented with the option of not selecting a type 2 parent.... one way I can think of doing this is having an option of "undisclosed" as a type 2 parent.. DO you have any other suggestions?.

2. after a user has added a parent with the relationship form they should be given the option to add another type 2 parent. I am not sure how to achieve this... checking if the field is empty only works after the form is submitted?

I read... https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/ but couldn't find an answer.

I also tried to follow
https://toolset.com/forums/topic/multi-select-with-filter-for-taxonomy-field-on-cred-form/ but I couldn't get that to work.

3. if the user cannot find the matching type 2 parent they should be given the option to enter another parent not on the list. I am thinking that this would be a third part of the form where they either create a type 2 parent post OR edit the child post by adding the Parent name as post content (the WP field). How would I achieve this?

4. Submit button not displaying or working. I have fiddled with it but can't seem to get this working

Any chance you can help with the above?

Thanks again.

Peter

#1672343

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Peter,

I think that Generic fields and some custom code will help with all these scenarios. The submit button is definitely an issue needing debugging and analysis.
But to answer all the other questions, I'll need to take a closer look at what you have done so far.
Would you allow me temporary access to check it further? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1672421

Jamal

I have another live support which directly overlaps this one... I was hoping that would be resolved first... But I gave access on that one earlier today and would be happy for you to address both. the ticket is https://toolset.com/forums/topic/cred-link-not-working/ currently with Shane

Thanks Peter

#1673237

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Thank you Peter for the access, they are working for me.

I tried to understand what forms are involved, there is only one relationship form, but I'll need some context, to understand what pages, forms, custom code, etc. are involved in the process. Can you provide detailed steps of what you want to achieve, for example:
- Visitor should visit the page ...
- Enter data(fields, etc.) into the form.
- Submit the form, it will redirect to ...
- etc.

#1673813

Jamal

What I am after help on is the second stage of the process for a business owner to report that their company has received investment. This can either be done from the profile page for their company OR from a "my profiles" page.

In stage 1 they click on a button to take them to a form where they enter data into the form to create a child post for the investment. - I had this working but it is currently broken and the subject of another support request. The only custom code was to create a title for the post created from a combination of fields entered.

Stage 2 - They can see what they have entered already and are shown a second form (the relationship form) where they select the name of the investor/s from options already loaded into the platform.

If their investor is not on the list they need to have the option to name one or more investors for which the system admins can create a profile.

then they are directed to a success page or a success message is displayed.

For context we mostly capture these investments from press stories. These are imported to the platform. This is a new feature for companies to report the investments themselves.

I hope that clarifies things.

Thanks again.

Peter

#1674177

Jamal

Thinking about this overnight ...
I forgot to highlight that the user needs to be given the option to select more than one Type 2 parent...and I think the way this second form should work is to let a user add one of the type two parent enter submit and then show the post with the parent added, with the option to add another parent.

I will then add CRED link to an edit form for the child post and a "I have finished button" which directs them to a page.

So I am left with the following problems 3 and 4 from above...

3. which I think I can address with an edit child post form.

4. the submit button which I can't get to work. Could you please see if you can figure out what is wrong with it?

cheers

Peter

#1674855

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello Peter, I'll do my best to help. I now understand your process a bit, but I'll still need some precisions, otherwise, I might be analyzing on the wrong place.
Can you provide for each of the steps you mentioned, either the URL where to see the form or the Forms IDs?
Can you also provide a simple example, I'll be trying with, like titles, names, amounts for an example scenario and the expected results?

I am sure you will understand, that I am not accustomed to your data model or the whole process. The many details/examples you will provide the more it will help me understand your needs very well.

#1680809

Jamal

Thanks for your response.

As described before this form that is causing me problems is part 2 in the process of a User creating a new funding event post.... The first part is now working well... thanks to Shane's help (see https://toolset.com/forums/topic/cred-link-not-working/#post-1675747)

The first part is a form that can be used by the owner of a company profile to report that their company has received funding (form 62129 - "New Funding Event - 2".

That form can be accessed on the following page under the company logo ... look for the button "Add a new Funding Event." (Please hide this link) hidden link

Form 62129 contains a number of fields... including a hidden field that sets the Company as parent of the Funding Event child post.

Once that form is submitted the new child post is displayed via the content template for funding events (#62199). That content template contains the relationship form so the user can select an investor (completing reporting the funding event).

I have finally got the submit button working but I am having difficulty setting the relationship form and content template up properly to enable the user to add more than one type 2 parent. What I hope to achieve is once one type 2 parent is added the user continues to see the content template for the child post also showing the type 2 parent they have just selected and is shown the form again and can add a second type 2 parent etc... until they elect not to add any more. Any ideas how I can achieve this?

Another thing that has me stumped is getting the submit button properly formatted. regardless of what I have tried I just get a small block of colour with no text, whereas it should say "Submit".

Thanks in anticipation

Peter

#1683159

Hi Jamal

I am keen to get this working.

Just wondering how are you going with my support request?

Cheers

Peter

The topic ‘[Closed] adding selector for second parent in form’ is closed to new replies.