Skip Navigation

[Resolved] Create new posts in 2 different post types and connect them with front end form

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

This topic contains 11 replies, has 2 voices.

Last updated by tobiasF-3 4 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1388301

I have a contact post type and an actor profile post type. The contact post type holds the general info about a contact like name, address, phone, etc. The actor profile post type is in related to the contact post type as child. The actor profile contact is attached to the contact post type for contacts that are defined as actors.

On the list with all actors, I would like to add a button to
'add a new actor'

it should then display a form for creating a new contact, where the user first enters all the general information.
Then the user should be directed to the 'add actor profile' form where he can enter the actor specific information.

When submitting, the user should be directed to the newly generated acting profile post. And in the background, the newly created contact post type and actor profile post type should be connected with a relationship.

1. is this the right approach? if not, please enlighten me 🙂
2. if yes: how do I build this?

Thank you very much
Tobias

#1388573

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand, you first want to create the parent post entry and on submit of that parent form you want to redirect the user on the page where child form is added and when the child form is submitted you want to connect the parent with child.

I suggest you should check the following Doc first:
=> https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

So, basically, you should do that and use the Toolset form's redirection hook "cred_success_redirect" so you should redirect the user to the page where you added the child form.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

So, technically, create a page X where you add the parent form and then create another page Y where you add the child form. When you submit the parent form on page x, use the "cred_success_redirect" hook and redirect the user of page Y and add parent post ID as URL param where child form is added.

Does this sound good?

#1394977

Hey Minesh, thx for the answer and sorry for the late reply, I was busy lately. I will try this out and will get back to you asap. Thx T

#1469085

Hey Minesh, sorry for the very long wait, I am back and have tried your solution, What I am struggling with is how to include the ID of the parent post in the URL param so that I can read it in the child form. Can you help me out? Thanks a lot. Tobias

#1469123

Minesh
Supporter

Languages: English (English )

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

Ok - I've reopened the ticket.

If you can share the problem URL where you added the form and tell me where exactly you want to redirect the user, I would be happy to check and adjust the hook for you.

*** 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 have set the next reply to private which means only you and I have access to it.

#1469701

Hey Minesh, sorry, I've just realised I've given you the wrong ftp folder info: you do NOT need the /tools.stories.ch/ part - you can just use the ftp credentials as I have given you, without a subfolder. Sorry about that. Cheers Tobi

#1470531

Minesh
Supporter

Languages: English (English )

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

I see the form but I would like to know what is your parent page? Have you added the create child post link to your parent post?

Can you please share the URL of the parent page.

#1470627

Here's the parent form (click on the blue button 'add actor')
hidden link

Thx!
Tobi

#1470689

Minesh
Supporter

Languages: English (English )

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

Well - I see you are using the following form:
=> hidden link

Now, if you see the page, I've added the "Create New" link that will redirect the user to "Add New Actor Profile" page:
=> hidden link

As the form creates a new entry, there is a field "Contacts Actor Profiles" available to connect with your new entry. I'm still not sure what parent you want to link to your profile?

#1470819

Hmm, I think we are misunderstanding each other. The parent is the contact. The child is the actor profile. The button that creates the parent form is on this page:
hidden link

When you click the blue button 'add actor', it brings the user to the parent form to create a contact. then by clicking on ^next page' in the form, it brings the user to the add actor profile which creates the child post type.

Does that makes sense?

Thx
Tobi

#1470855

Minesh
Supporter

Languages: English (English )

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

This is how you should share your workflow and information that will help us to guide you in the right direction.

So, I've added the following code to the "Custom Code" section offered by Toolset with the snippet "redirect-to-actor-profile"
=> hidden link

add_filter('cred_success_redirect', 'func_redirect_user_to_actor_profile',10,3);
function func_redirect_user_to_actor_profile($url, $post_id, $form_data) {
    if ($form_data['id']==4765)
        return '/add-new-actor-profile/?parent_id='.$post_id;
   
    return $url;
}

And within your child form:
=> hidden link

I've changed the urlparam attribute for the parent field to parent_id:

<div class="row">
		<div class="form-group col-md-12">
			<label>Contacts Actor Profiles</label>
			[cred_field field='@contact-actor-profile.parent' class='form-control' output='bootstrap' select_text='--- not set ---' urlparam='parent_id']
		</div>
	</div>

Can you please confirm it works now 🙂

#1470871

Thank you Minesh, this works perfectly now. I see how you added the $post_id element to the snippet. I was missing that one 🙂

I hope I understood the process enough, so I can create similar connections now by myself in the future, otherwise, I will just come back... 🙂

My issue is resolved now. Thank you!