Skip Navigation

[Resolved] Linking Post Form and Relationship Form

This support ticket is created 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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: Asia/Karachi (GMT+05:00)

Author
Posts
#2254689

Tell us what you are trying to do?
I have a new website, where I want to link Questions, Views (not a Toolset View) and Minds. There are two many-to-many relationships, between Questions and Views and between Views and Minds.

What I now have is this form: hidden link
But the Relations are not connected to the actual Questions and Minds.

What I want is that users can submit their View (Post Form) and connect those to Questions and Minds (Relationship Form).

Is there any documentation that you are following?
I found that you can not combine the Post Form and Relationship Form into one page.

So I thought: is it possible to make some kind of frontend wizard, where you first submit the Post form and the submit-button (which is called 'Next step' or 'Continue') takes you to the Relationship Form, where the View is automatically filled in and you only have to select the right Questions and Minds. And then you click Submit. The View (as a total) is then saved as 'pending for review'

Thanks in advance!

#2255247

Hi,

Thank you for contacting us and I'd be happy to assist.

Your understanding is correct and for the many-to-many relationships, you'll have to use the post form and the relationship forms, separately.

To achieve something similar, you can follow these steps:

1. You can create a new page "Add New View" that will include a post form to add a new "View" post. On form submission, you can set the form to redirect to the newly created post.

2. Next, you'll create 2 relationship forms:
- Form to connect View and Question
- Form to connect View and Mind

3. In the content template for the single "View" post, you can include these two forms, using their shortcodes:


[cred-relationship-form form='form-to-connect-view-and-question' child_item='$current']

[cred-relationship-form form='form-to-connect-view-and-mind' child_item='$current']

The child_item='$current' part will make sure that that current view post is automatically selected in the relationship form field and the user just has to select the question and mind post in their respective fields.
(you can even hide the view selection field using CSS code, as the user doesn't need to see or fill that)

As a result, after creating a view post, the user can come to its single post page and connect as many questions and minds to it, one by one, using the respective forms.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2255593

Thank you, much appreciated. I'm getting it to work for the biggest part.

I have a couple of additional questions to finish it.

On hidden link (example of a view) you can see two areas: Links and Minds.
1. The Links Add-button fires up a bootstrap modal with the form for a repeatable field group, but the current view is not selected, the shortcode I use is [cred-form form="add-resources-to-view" child_item='$current']. What should I change to have the current view selected and greyed out?
2. The Minds Add-button also fires up a modal where all minds can be selected, but there is no button to add a new one. What should I do to make that work? It is a many to many relationship.

And the third and last question.
3. On hidden link (example of a question), you see the 'Add' button at the overview of the views. This links to the View-form, where I would like the new View to be automatically connected to the question where the add-button was clicked. How do I get this done?

Thanks in advance!

#2255983

Thanks for writing back.

1. When I click the "Add Link" button, I see the modal window, but there is no form inside it. Also, you mention the form for the "repeatable field group", whereas, from your earlier message, I thought, links were also a separate custom post type.

Can you please share temporary admin login details so that I can see how these items are set up in the admin area?

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

2. The button "Add Mind" is showing the relationship form correctly, with the current view selected.

You can't add a new post item using the relationship form, so for this, you can include another post form in this same modal window, that can be used to add a new "Mind" post.

3. To achieve this, you can pass the current question post's ID using the shortcode "[wpv-post-id]" in the URL parameter "question" for the link to add a new view post, for example:


/vadd/?question=[wpv-post-id]

When a user will use this link and reach the "Add a new View" page, the referring question's ID will be available in the "question" URL parameter. You can fill this ID in a hidden generic field, and then use the "cred_save_data" hook ( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data ), to programmatically connect the newly created view post and the referring question post, through the "toolset_connect_posts" function ( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts ), on the form's submission.

#2259219

Thank you for sharing these details, but the username and password that you shared are not working.

Can you please test the username and password again?

I'm setting your next reply as private.

#2260119

I was able to access the website's admin area, thank you.

1. To make sure that the newly created "Mind" post gets connected to the current "Answer" post, when the form is submitted, you can a custom function attached to the "cred_save_data" hook ( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data ), that uses the "toolset_connect_posts" function ( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts ) to join the two posts.

For example:


add_action('cred_save_data', 'join_new_mind_current_answer',10,2);
function join_new_mind_current_answer($post_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==928)
	{
		if (isset($_POST['_cred_cred_prefix_cred_container_id']))
		{
			toolset_connect_posts( 'cocreator-view', $post_id, $_POST['_cred_cred_prefix_cred_container_id'] );
		}
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

Please note the use of the form ID "928" which for the form named "Add Mind" and the relationship slug "cocreator-view" for the relationship "Minds Answers".

2. To automatically select the current "Answer" post in the "View" of the form "Add Resources to View", you can include the shortcode [wpv-post-id] in that field's default value.
( screenshot: hidden link )

As a result, when the form will load, the current answer post will be automatically selected in the "View" field.

And to hide this field, so that user can't change its value, you can include this custom CSS code in the form's CSS editor:
( screenshot: hidden link )


#cred_form_755_1_1 .form-group:nth-of-type(4) {display: none;}

#2262035

Works like a charm, thanks!

My issue is resolved now. Thank you!