Skip Navigation

[Resolved] Which hook to use AFTER form submit to store data in table

This support ticket is created 3 years, 8 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 – 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)

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by himanshuS 3 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1990855

I want to store custom data based on computation of newly updated post data in a custom table.

Sequence: 1) enter data in cred post form, 2) submit cred post form 3) standard tables get updated 4) I run my code to compute data from the updated standard tables to store in a custom table AFTER specific forms are submitted.

I want the code to be triggered after the cred post form is submitted but I don't want the code to delay the redirection from the form i.e. user should not be have to wait while this code runs. It could run in the background and do it's job and user can continue with their work.

My question: What is the right hook to use here that allows me to trigger the code after a specific form submit? I can't use cred_success_redirect as it will delay the user experience. Is there another hook I can use that allows me to filter execution by cred form id?

#1991183

Shane
Supporter

Languages: English (English )

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

Hi Himanshu,

You can use the hook below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete

This hook fires after the post has been saved but before the redirect triggers.

Please let me know if this helps.
Thanks,
Shane

#1991221

Shane,

I think I did not explain the issue clearly. I want to be able to trigger custom code after the post has been published and the user has been directed to the new page (if that's the case) or has received a message in the form.

If I use the cred_submit_complete hook, it will stall the redirection until my code is executed. I don't want that. I want the user to continue using the site while this custom code is triggered in the background AND I want the code to be triggered only when a specific form id is submitted.

#1991249

Shane
Supporter

Languages: English (English )

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

Hi Himanshu,

It would need to be the cred_redirect_success hook as after this hook no other Hooks related to the form is fired.

You're essentially limited to the hooks that we have available for the various stages of the form submission.

Thanks,
Shane

#1993687

Shane,

I had another thought on using the on-demand feature of the toolset custom code to trigger the action.

What if I add the script to the URL parameter when redirection happens? This way the user gets redirected to the post and I append the script as a URL parameter to the post URL.

Link here: hidden link

My question: will the redirection of the user the post get delayed until this script in the URL is processed?

#1993787

Shane
Supporter

Languages: English (English )

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

Hi Himanshu,

This can work however how will you be adding it to the URL? using the redirect hook ?

Any extra code will have a delay effect on the redirection since adding the url parameter is before the return statement. There will be delay but if it will be a noticeable delay I believe not.

This will then allow you to fire your custom code after the redirect is done since it is listening for the URL parameter.

Please let me know if this helps.
Thanks,
Shane

#1993855

That's exactly what I want to do. Use redirect hook to override the form setting to display post.

Last question: will the redirect hook override the form settings to redirect to the posturl?/call-to-execute-code?

#1993873

Shane
Supporter

Languages: English (English )

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

Hi Himanshu,

Yes it will overwrite the form settings to redirect because the redirect hook returns the url to redirect to.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

So in the hook you will need to redefine the redirect url as well as append the attribute to the url.

Thanks,
Shane

#1993885

Perfect. My issue is resolved now. Thank you, Shane.