Skip Navigation

[Resolved] Error on post submission – can't render the template and no relationship formed

This support ticket is created 3 years, 10 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/Karachi (GMT+05:00)

This topic contains 5 replies, has 3 voices.

Last updated by himanshuS 3 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1904521
Post to submit.png
error message.png
no association formed.png
form setup.png
form setup 2.png

I am trying to:
create a post using the post form.

Link to a page where the issue can be seen: hidden link

I expected to see: the post in the post template format.

Instead, I got: error page. There has been a critical error on this website.

#1905201

Nigel
Supporter

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

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

The error occurs when you submit a form, is that correct?

Do you have any custom code running (using the Forms API, for example)? If so, does the error occur when you disable it?

Does the error occur if you disable non-Toolset plugins?

Do you have details of the error?

If you haven't already, turn on the debug log by editing your wp-config.php file and change the line with WP_DEBUG like so:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

That will create a debug.log file in your /wp-content/ directory which you can examine in any text editor.

Try submitting the form again and then inspect the log. Please share what you find.

#1905457

Nigel,
I think I found the issue. I have a custom code that helps me populate the grandparent author's email to the post so that CRED's form notification system can send an email on submit. It seems to be causing a conflict.

The code:
add_action('cred_save_data', 'populate_expert_review_requester_email_on_expert_review',10,2);
function populate_expert_review_requester_email_on_expert_review($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==10447 || $form_data['id']==10448)
{
$expert_match_id = toolset_get_related_post($post_id, 'expert-match-to-expert-review', 'parent', 'publish');
$expert_review_request_id = toolset_get_related_post($expert_match_id, 'expert-review-request-to-expert-match', 'parent', 'publish');
$expert_review_request = get_post( $expert_review_request_id);
$expert_review_requester_id = $expert_review_request->post_author;
$expert_review_requester_email = the_author_meta('user_email', $expert_review_requester_id);
update_post_meta($post_id,'wpcf-expert-review-requester-email', $expert_review_requester_email);
}
}

The log:
[14-Jan-2021 14:30:08 UTC] PHP Fatal error: Uncaught InvalidArgumentException: All provided arguments for a related element must be either an ID or a WP_Post object. in /srv/htdocs/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php:246
Stack trace:
#0 /srv/htdocs/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php(177): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->set_query_by_elements(Array, 'child')
#1 /srv/htdocs/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/public_api/m2m.php(159): OTGS\Toolset\Common\Interop\Commands\RelatedPosts->__construct(0, 'expert-review-r...', Array)
#2 /srv/htdocs/wp-content/toolset-customizations/add-expert-review-requester-email-to-expert-review.php(16): toolset_get_related_post(0, 'expert-review-r...', 'parent', 'publish')
#3 /wordpress/core/5.6/wp-includes/class-wp-hook.php(287): populate_expert_review_requester_email_on_expert_review(11391, Array)
#4 /wordpress/core/5.6/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#5 /wordpress/core/5.6/wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#6 /srv/htdocs/wp-content/plugins/cred-frontend-editor/application/models/form/post.php(639): do_action('cred_save_data', 11391, Array)
#7 /srv/htdocs/wp-content/plugins/cred-frontend-editor/application/models/form/base.php(434): CRED_Form_Post->save_form(11391)
#8 /srv/htdocs/wp-content/plugins/cred-frontend-editor/application/controllers/form_builder_base.php(40): CRED_Form_Base->print_form()
#9 /srv/htdocs/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/CRED_Helper.php(1855): CRED_Form_Builder_Base->get_form(10447, '')
#10 /srv/htdocs/wp-content/plugins/cred-frontend-editor/library/toolset/cred/embedded/classes/CRED_Helper.php(2451): CRED_Helper::cred_form('submit-expert-r...', '')
#11 /wordpress/core/5.6/wp-includes/shortcodes.php(343): CRED_Helper::credFormShortcode(Array, '', 'cred_form')
#12 [internal function]: do_shortcode_tag(Array)
#13 /wordpress/core/5.6/wp-includes/shortcodes.php(218): preg_replace_callback('/\\[(\\[?)(cred_f...', 'do_shortcode_ta...', '[cred_form form...')
#14 /srv/htdocs/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/handler/elementor/widgets/base.php(124): do_shortcode('[cred_form form...')
#15 /srv/htdocs/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/handler/elementor/widgets/form/form.php(116): OTGS\Toolset\Common\Interop\Handler\Elementor\ToolsetElementorWidgetBase->render_frontend_widget()
#16 /srv/htdocs/wp-content/plugins/elementor/includes/base/controls-stack.php(1894): OTGS\Toolset\Common\Interop\Handler\Elementor\FormWidget->render()
#17 /srv/htdocs/wp-content/plugins/elementor/includes/base/widget-base.php(530): Elementor\Controls_Stack->render_by_mode()
#18 /srv/htdocs/wp-content/plugins/elementor/includes/base/widget-base.php(660): Elementor\Widget_Base->render_content()
#19 /srv/htdocs/wp-content/plugins/elementor/includes/base/element-base.php(644): Elementor\Widget_Base->_print_content()
#20 /srv/htdocs/wp-content/plugins/elementor/includes/base/element-base.php(864): Elementor\Element_Base->print_element()
#21 /srv/htdocs/wp-content/plugins/elementor/includes/base/element-base.php(644): Elementor\Element_Base->_print_content()
#22 /srv/htdocs/wp-content/plugins/elementor/includes/base/element-base.php(864): Elementor\Element_Base->print_element()
#23 /srv/htdocs/wp-content/plugins/elementor/includes/base/element-base.php(644): Elementor\Element_Base->_print_content()
#24 /srv/htdocs/wp-content/plugins/elementor/core/base/document.php(1252): Elementor\Element_Base->print_element()
#25 /srv/htdocs/wp-content/plugins/elementor/core/base/document.php(889): Elementor\Core\Base\Document->print_elements(Array)
#26 /srv/htdocs/wp-content/plugins/elementor/includes/frontend.php(975): Elementor\Core\Base\Document->print_elements_with_wrapper(Array)
#27 /srv/htdocs/wp-content/plugins/elementor/includes/frontend.php(889): Elementor\Frontend->get_builder_content(10649)
#28 /wordpress/core/5.6/wp-includes/class-wp-hook.php(287): Elementor\Frontend->apply_builder_in_content('<h1>Submit Expe...')
#29 /wordpress/core/5.6/wp-includes/plugin.php(212): WP_Hook->apply_filters('<h1>Submit Expe...', Array)
#30 /wordpress/core/5.6/wp-includes/post-template.php(253): apply_filters('the_content', '<h1>Submit Expe...')
#31 /srv/htdocs/wp-content/themes/astra/template-parts/content-page.php(59): the_content()
#32 /wordpress/core/5.6/wp-includes/template.php(732): require('/srv/htdocs/wp-...')
#33 /wordpress/core/5.6/wp-includes/template.php(676): load_template('/srv/htdocs/wp-...', false, Array)
#34 /wordpress/core/5.6/wp-includes/general-template.php(204): locate_template(Array, true, false, Array)
#35 /srv/htdocs/wp-content/themes/astra/inc/class-astra-loop.php(109): get_template_part('template-parts/...', 'page')
#36 /wordpress/core/5.6/wp-includes/class-wp-hook.php(287): Astra_Loop->template_parts_page('')
#37 /wordpress/core/5.6/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
#38 /wordpress/core/5.6/wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#39 /srv/htdocs/wp-content/themes/astra/inc/class-astra-loop.php(199): do_action('astra_page_temp...')
#40 /srv/htdocs/wp-content/themes/astra/inc/class-astra-loop.php(174): Astra_Loop->loop_markup(true)
#41 /wordpress/core/5.6/wp-includes/class-wp-hook.php(287): Astra_Loop->loop_markup_page('')
#42 /wordpress/core/5.6/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
#43 /wordpress/core/5.6/wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#44 /srv/htdocs/wp-content/themes/astra/inc/core/theme-hooks.php(267): do_action('astra_content_p...')
#45 /srv/htdocs/wp-content/themes/astra/page.php(32): astra_content_page_loop()
#46 /wordpress/core/5.6/wp-includes/template-loader.php(106): include('/srv/htdocs/wp-...')
#47 /wordpress/core/5.6/wp-blog-header.php(19): require_once('/wordpress/core...')
#48 /wordpress/core/5.6/index.php(17): require('/wordpress/core...')
#49 {main}
thrown in /srv/htdocs/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/inc/autoloaded/interop/commands/RelatedPosts.php on line 246

#1906381

Hi,

Thank you for sharing these details.

Based on my testing, this error would be shown if the "$expert_match_id" in your code snippet is empty or doesn't exist.

In the case of an edit post form, this would happen if there is no parent post is set in the "expert-match-to-expert-review" relationship.

And in the case of a new post form, this would always happen, since, during the processing of this code snippet, the selected parent hasn't been set yet.

To make this code work for the new and edit forms alike, you can update it to get the value from the global variable "$_POST":


add_action('cred_save_data', 'populate_expert_review_requester_email_on_expert_review',10,2);
function populate_expert_review_requester_email_on_expert_review($post_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==10447  || $form_data['id']==10448)
	{
		$expert_match_id = $_POST['@expert-match-to-expert-review_parent'];
		$expert_review_request_id = toolset_get_related_post($expert_match_id, 'expert-review-request-to-expert-match', 'parent', 'publish');
		$expert_review_request = get_post( $expert_review_request_id);
		$expert_review_requester_id = $expert_review_request->post_author;
		$expert_review_requester_email = the_author_meta('user_email', $expert_review_requester_id);
		update_post_meta($post_id,'wpcf-expert-review-requester-email', $expert_review_requester_email);
	}
}

Note: For step-by-step custom code troubleshooting, you'll find the "WP PHP Console" plugin ( https://wordpress.org/plugins/wp-php-console/ ) very useful, as it makes PHP errors and warnings much simpler to trace.

regards,
Waqar

#1906857

That worked! Thanks Waqar.

#1906869

My issue is resolved now. Thank you!