Skip Navigation

[Resolved] Automatically set post parent in post form from URL parameter

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

Problem:
Automatically set post parent with Toolset CRED form using new post relationship

Solution:
You can use new post relationship API function 'toolset_connect_posts' in order to connect two posts in relationship of parent and child in conjunction with the use of cred_save_data hook.

For example:

add_action('cred_save_data','func_custom_post_title',15,2);
function func_custom_post_title($post_id,$form_data) {
    if ($form_data['id']==243) {
         
        toolset_connect_posts('boat-safety-check',$_POST['@boat-safety-check_parent'], $post_id);
    }
}

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/automatically-set-post-parent-in-post-form-from-url-parameter/page/2/#post-902786

Relevant Documentation:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 5 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Author
Posts
#878401

I'm setting up a post form for a post type "Safety Checks" that is set with a post relationship as a child of a post type "Vehicles"

I have the id of the vehicle set in the URL ?vehicle_id=60

My question is this: how can I pull that ID into this part of the post form:

<div class="form-group">
<label>Safety Checks</label>
[cred_field field='@safety-check.parent' select_text='--- not set ---' class='form-control' output='bootstrap']
</div>

Rather than having a select drop-down, I want it to be automatically set based on that URL parameter?

#878829

You don't need to.

If you already have a Page or Post where you can dynamically append the URL parameter, all you need to do is insert the Form on that page.

Let's say you have 2 Post Types, child and parent
You create a Form to add new Child posts.
You add this form to a Page, where you dynamically pass the URL parameter (?parent_toolset-parent_id=15)
When you visit that page, the Form will already have the Parent Selector set to the parent post with ID 15.

Toolset Forms Parent Selector basically already listens automatically to the URL parameter you mention, there is no need to pass it again to the ShortCode.

You can entirely hide that Field, with some HTML, and pass the parent just with the URL parameter.

#901976

OK, so i've set up a content template for the vehicle, and in that content template is a view that lists all "safety checks" that are children of the current vehicle, as well as a cred form to add a new safety check.

There's a dropdown selector (I just autogenerated the form) that lists out the possible vehicles. But, it isn't pre-selected with the current vehicle, nor when you set the vehicle does it save the relationship? Any idea on what might be going on there? I can provide a login if needed- just recently set up a dev install for the site.

#902002

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Yes, could you please share problem URL and access details so I can check whats going wrong there.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#902171

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I could not able to login, When I try to login, it again shows authorization popup and page get stuck. Could yo please make simpler login to I can access the backend.

#902244

Ah ok, have removed now. Should be fine

#902373

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - still I'm facing same issue, login page is loaded successfully but once I enter user/pass and click on submit button the authorization popup shown and I cant able to login.

Could you please fix this issue and send me working wp-admin access details.

#902408

Can you try incognito? It is all working perfectly fine at my end....

#902412

Or at least send me a screenshot of what you mean?

#902446

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I tried incognito window - does not help.

Here is the steps I follow:
=> I load this URL: hidden link
=> enter username and password and when I click on "Login" button
=> It throws authorization popup - and when I enter the details you shared with username "flux" and password its not working - its just not let me allow to login to wp-admin.

#902454

You're using the username "brad", right? There is no longer any kind of protection on the site- i've tried it on three different machines here, different browsers- all work perfectly fine.

Can you try a different browser? A different machine? Has to be some kind of caching issue at your end since everything else loads it fine. hidden link

#902461

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

error-1111.jpg

Yes - I use "brad" user name to login to wp-admin and "flux" username to login to authorization popup.
Well - I checked with my another college and he also experience the same problem.

As you can see with the attached image - first page loads fine with login form URL: hidden link
=> I enter username and password and when as soon as I click on "Login" button
=> It throws authorization popup (as you can see with attached image) - and when I enter the details you shared with username "flux" and password its not working - its just not let me allow to login to wp-admin.

#902476

Try user "u" and password "2" for that popup. Looks like my hosting adds its own brute force protection for some reason.

#902485

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - Now I'm able to get in and login. Thank you.

You said:
I have the id of the vehicle set in the URL ?vehicle_id=60
==> I do not see the URL param vehicle_id in URL - could you please send me direct link where I can see this ID.

#902501

That was the old setup- the next post from support said I don't need to do that. If you take a look through my next 2 posts #901976 and #902007 youll se that the form to create the child post is nested in the parent vehicle template. It populates the auto-generated dropdown correctly, but there are 2 problems:
1- it isn't pre-set with the current parent vehicle
2- even if you manually select the parent vehicle, it isn't saved/linked

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.