Skip Navigation

[Resolved] Form notifications without creating post

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

Problem:
Client wants to use Toolset Form notifications as contact forms, without storing the submitted posts in the database.

Solution:
Forms will always publish a post. If you don't want those posts to be retained, you could

1. add post expiration and have the posts trashed within minutes of them being published. This won't delete them, you would need to use some kind of utility to routinely empty the trash; or
2. use the CRED API to run some code once the form had been submitted and then delete the post. The latest effective hook that could be used in this case would be the cred_notification_recipients hook.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ljuba 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#958379

=> Tell us what you are trying to do?

Is it the way to create form what will use data from CPT, but will not create posts?

EXPLANATION

CPT (Hotels) have child post (Rooms). CRED Booking form should to use data from CPTs (ie - from Rooms > Room Types for specific/current parent post - ie Hotel XXX1 and from Hotels > owner Email - to be able to send notification).

Here are two questions:

1) (less important) Can I add non existing field(s) to form (as I don't want post creation)? I wrote that it is less important as I guess that I can to use any of available fields and to 'mask' titles in CRED, as for final form submitted result, I want that form will not create the post (so, if next is possible). However, it is also not so big deal to get another simple child CPT for form creation results (as it will not be populated by posts).

Is it right?

2) How to disable creation of the posts by the form (I guess that I can manually change 'Status of the post after submitting the form:' to not available option in dropdown > 'Delete', as that is basically all what I want)?

REASONS FOR REQUEST

I don't want to store thousands (or much more) of bookings (posts) on the server, as goal of the project is not to do it. it is only need for simple service of 'Booking service' with only feature of 'Email notifications'.

#958757

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Ljuba

CRED Forms will always publish a post, that's what they are for.

If you want to use the notifications system of CRED for contact forms you can, but you'll need to make sure the posts created by the forms are deleted.

One way would be to set post expirations for the posts created by the forms so that they are trashed a few minutes after submission. Then you would need some house-keeping utility that routinely deleted the posts that are in the trash.

Or you can try the CRED API and add a couple of lines of PHP to delete the post pretty much as soon as it has been created.

You could use the cred_submit_complete hook, except I believe this is triggered before the notifications have been sent, and if the underlying post has already been deleted I suspect the notifications might fail (you would have to try and see for yourself).

So you could, instead, try the cred_notification_recipients filter to add the code to delete the underlying post. I think, by then, the notification has gathered all the required data, but, again, you would need to try it and see.

You can add generic fields to a form which are not saved but which should be available in your notifications (as long as the notification is sent when the form is published and not at some later point) or which would be available in the $_POST object in code you add using CRED hooks.

https://toolset.com/documentation/programmer-reference/cred-api/
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

#958764

Thanks. That's exactly all what I needed.