Problem: I am using the cred_save_data Forms API with new and edit post Forms that create or edit child posts in a O2M post relationship. The Form contains a post relationship field where I have defined the parent using a URL parameter. I get a 500 error when submitting the Form with AJAX.
Solution: Do not rely on the $_GET superglobal to access values in URL parameters. AJAX submissions do not have access to the parent page's URL params in $_GET. Instead, it is better to use a hidden field in the Form using the URL parameter option to store the parent page's URL parameter value in the Form. Then you can access that value in a cred_save_data hook in the $_POST superglobal instead. This approach will work well in either AJAX or standard Form submissions.
It is also important to note that the post relationship managed in the Form will not be available to the Post Relationships API during a cred_save_data hook. Relationships are not established by the time the hook fires, so you would have to get the relationship field value directly from $_POST in a cred_save_data hook. Or, use a cred_submit_complete hook. Post relationshps are available in the Post Relationships API at the time of cred_submit_complete.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 10 replies, has 3 voices.
Last updated by 3 years, 8 months ago.
Assisted by: Christian Cox.