Skip Navigation

[Resolved] JavaScript form field validation running in one but not the other page

This support ticket is created 5 years, 1 month 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 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1391939
dev.astrofamilystory.com-report-details-page-validation-2019.11.26-11_29_12.png
dev.astrofamilystory.com-members-page-error-2019.11.26-11_22_04.png

I am trying to:
There is a form field "Place of birth" look-up in place to a third party data service in the add-member-form that works fine when used on the Reports details page. But not when used on the Members page.

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

I expected to see:
A validation statement under the Place of birth field either stating "Place Found" or "Place not Found", please see attached screenshot. That works on the Reports details page, i.e. hidden link

Instead, I got:
A fatal error occurred message, please see attached screenshot. That occurs on the hidden link using the same add-member-form.

This I believe is a continuation of a support request for defining form to post relationships and subsequent changes made to the form in question (https://toolset.com/forums/topic/automatically-connect-post-created-with-form-to-an-existing-post-using-post-relationships/)

To troubleshot this myself I have created a duplicate of the add-member-form-general and have taken out the conditional statement:
[wpv-conditional if="( '[wpv-post-id item="$current_page"]' ne '498' )"]
<div class="row">
<div class="col-md-12">
[cred_generic_field type='hidden' field='connect-to-report']
{
"default":"[wpv-post-id]"
}
[/cred_generic_field]
</div>
</div>

But then no validation would occur and the new member would be created with what ever values were entered.

#1392193

Hello,

Thanks for the details, I can log into your website and see the problem you mentioned above.

And they are different problems.
1) The PHP error in screenshot:
https://toolset.com/wp-content/uploads/2019/11/1391939-dev.astrofamilystory.com_members_page_error_2019.11.26_11_22_04.png
It is produced by the custom PHP codes of your theme file "functions.php", line 100~107:

add_action('cred_save_data', 'tssupp_connect_member_to_report',10,2);
function tssupp_connect_member_to_report($post_id, $form_data) {
	$forms = array( 94 );
	if ( in_array( $form_data['id'], $forms ) )	{
		$report_id = $_POST["connect-to-report"];
		toolset_connect_posts( 'report-members', $report_id, $post_id);
	}
}

Since the field "connect-to-report" can be hidden by [wpv-conditional] shortcode, so there might not be "connect-to-report" POST variable, and you will get the PHP error message as the screenshot.

I suggest you try to change it as below:

add_action('cred_save_data', 'tssupp_connect_member_to_report',10,2);
function tssupp_connect_member_to_report($post_id, $form_data) {
	$forms = array( 94 );
	if ( in_array( $form_data['id'], $forms ) && isset($_POST["connect-to-report"]))	{
		$report_id = $_POST["connect-to-report"];
		toolset_connect_posts( 'report-members', $report_id, $post_id);
	}
}

More help:
hidden link

2) But not when used on the Members page
This should be a problem of your custom JS codes in post form "Add Member Form general":
hidden link
section "Form editor", click "JS Editor", according to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/

I suggest you try those custom JS codes manually, line by line.

#1392709

Hi,

1) The PHP snipped in the functions.php was given to me by Christian Cox as that is seemingly the only way to link a form submission to an existing Custom Post Type. And has worked fine before only recently created that PHP error!? But I see the point that you need to query if the field is set or not by adding && isset($_POST["connect-to-report"]).

2) The JavaScript validation is only referencing existing form fields so should work wherever it is added!?
I have duplicated the CRED form and took out the connect-to-report snipped. But that also just worked for the reports details page but not for the members listing page. Again why does it work on one page but not the other!?

#1392899

1) Yes, as I mentioned above, in your case, you need to check if the "connect-to-report" existed.

2) Same as above, you are using [wpv-conditional] shortcode to check if current page is a specific page, and hide/remove some fields in forms, that can conduct the problem:
You custom JS codes work on one page but not the other