Skip Navigation

[Resolved] Create flow for user from parent cred form to child form and linking them

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 17 replies, has 2 voices.

Last updated by garyF-3 7 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#562874
CREDS-PARENT-AND-CHILD.jpg

Tell us what you are trying to do?
see attached image.

I have a creds form (form 1) that creates a parent post.
Another creds form (form 2) creates a child post of parent post

After submission of form 1 the parent post is created. How do you then link this to the creds form - using a redirect to page that has the form 2.

#562984

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

Thank you for contacting our support forum.

You can achieve this but it will take some setup.

First you need to create a page and add that child form to the page. The next step is to use the redirect hook to provide the child page with the parent page ID after you have created the parent.

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==12)
        return 'mychildform-page-url?parent_{parent_CPT_slug_here}_id='.$post_id;
    return $url;
}

Add the hook above to your functions.php file and then replace the relevant areas such as the url link the parent cpt and the form ID.

Please try this and let me know if it helps.
Thanks,
Shane

#563151

Hi, thank you for that code snippet\\
This is the code I added to the functions

add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
    if ($form_data['id']==12)
        return 'hidden link'.$post_id;
    return $url;
}

I think the syntax is correct?

This generated this url

hidden link

But it didn't then assign the child post to the parent.

#563154

Hi, apologies. This works fine. I made a mistake with the syntax when copying it over.

Thank you so much for your help - awesome.

It works perfectly

Gary

#563186
Form-Process-Flow.png

Sorry to open this again. I wondered if it is possible to extend this to another form - see image for process

#563278

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

So your saying your child post is a parent of another post?

If so then yes just copy the function and change its name and ID and information to match the relevant CPT and it should work.

Thanks,
Shane

#563365

Hi Shane, apologies for this. The more I understand the more I see the problem.

If you look at the flow process I have missed some important points out:

1. A user will only ever create 1 website.
2. The Custom Post Type A will be create several times using the same form e.g. on a page after submission the form is shown again so they create CPT Type A 1, CPT Type A 2, CPT Type A 3 until they have completed the number relevant to them. Each one though needs to assigned to the original Parent Post Type - Website (only 1 per user).
3. On the page with the website creds form for creating CPT Type A posts there is a button that then takes them to the next creds form.
4. This new creds form page creates CPT Type B posts. Each of these needs to be linked to the Parent Post Type - Website (only 1 per user).
5. The user will then create several of these CPT Type B posts - CPT Type B 1, CPT Type B 2, CPT Type B ...Each one needs to be linked to the Parent Post Type - Website.

So based on this and my understanding I think the question is - can a creds form based on a user be linked to a single parent post type using a filter or code or short code.

The website form are as follows if you want to take a look:
Parent Post Form
hidden link
Child Type A form
hidden link
Child Type B form
hidden link

thanks

Gary

#563373

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

I see what you are saying so you would want the user to keep creating more posts with the same parent as much as they like correct?

Please let me know.

Thanks,
Shane

#563383

Hi Shane, that's exactly it.

#563388

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

In this case the best thing I can think of is another redirect hook that would pass that same parent ID in the form again like this.

add_filter('cred_success_redirect', 'custom_redirect2',10,3);
function custom_redirect2($url, $post_id, $form_data)
{
    if ($form_data['id']==12 && isset($_GET['parent_website_id']))
        return '<em><u>hidden link</u></em>'.$_GET['parent_website_id'];
    return $url;
}

Please try this and let me know if it helps.
Thanks,
Shane

#564705

Hi, sorry for the delay in getting back to you. I don't think that will work. If you look at the flow diagram you may see why:

The website form are as follows if you want to take a look:
Parent Post Form
hidden link
Child Type A form
hidden link
Child Type B form
hidden link

To recap:
There will only be one website created by one user.
Each user will therefore after creating the site have one website id associated with them.
After completing the website the url data is passed to the next form, however
Each user can create more than one child post.
So the website form 2 they create more than one post - the question then is can the url redirect assign the parent post id on the creation of the 2nd, 3rd...child post?

The website form 2 has a button on it that once people have finished creating the child posts for form 2 takes them to the next form, if the filter only works on url parameter I can't see this working either.

A question is can a filter or hook/action be used that works on the submit or creation of a cred post that assigns it to the parent post (only one parent post will exist). So a query to the database for user find parent post id and then use this to identify parent id and assign to any child post created?

#564772

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

The Child Type B is of a different CPT ?

Also the code should work its just that we are not providing the right information. So after child type A is created the user should get redirected to Child Type B which is on a different page correct?

Also the user does have the option to assign the parent to the child when the child is created because there is a dropdown on the form to assign the parent to the child.

Please let me know.
Thanks,
Shane

#565808

Hi, I tested this and as I suspected it doesn't work. The parent id is passed to the first child post created but then every other one is an orphan. Is there a way to filter or link each creation to the parent post via user id.

So there will only be one website per user but multiple child posts.

#565937

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

Would you mind providing me with admin access to the website as well as a link to the first child and second child form.

The private fields have been enabled.

Please let me know.
Thanks,
Shane

#566920

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gary,

The private fields have been enabled.

Thanks,
Shane