Skip Navigation

[Resolved] Forms API / Post Relationships API to create form that redirects to parent post

This support ticket is created 6 years, 6 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#989812

I am at the very early stages (not even theming yet) of setting up a company portal application on a WordPress site. For the first stage, it will be used for employees to log in and fill out a timesheet.

For this piece of the project, I have parent-child post types created for Timesheet (the parent) and Timesheet Entry (the child). It is a one-to-many relationship meaning the Timesheet can have many Timesheet Entries but the Timesheet Entries is only associated with 1 Timesheet.

What I am trying to setup in the Timesheet View is similar model to what is demonstrated here in this article:
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected

Everything is almost setup but there is one thing that I would like to implement in this workflow. The timesheet view has a list of the related timesheet entries posted and a button to add more. When taken to the add Timesheet Entry form, it would be perfect if after submission the user is returned to the Timesheet view. Right now the best I can do is take the user to the Timesheet Entry post they just created but this is not really ideal.

I created a suggestion ticket asking to make Parent Post an option after form submission. This was the response and the suggestion was to use the Forms API and open up a How-To ticket: https://toolset.com/forums/topic/option-after-child-post-form-submission/

Thank you so much for your help.

#1054935

Hello,

Yes, it is possible to setup some custom PHP codes to redirect user to the parent post.

For example,
1) When user submits the Toolset form for creating/edting child "Timesheet Entries" post, use filter hook "cred_success_redirect" to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

2) In this PHP function get the parent "Timesheet" post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

and return the parent "Timesheet" post URL
https://developer.wordpress.org/reference/functions/get_permalink/

For your reference.