Skip Navigation

[Closed] Validate Address Field

This support ticket is created 2 years, 2 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/Hong_Kong (GMT+08:00)

This topic contains 7 replies, has 2 voices.

Last updated by Luo Yang 2 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#2286281

Hi, is there any way to validate the address field before a Cred form is submitted?
I just need to be sure that the user has entered a value that returns a valid longitude and latitude.
Thanks

#2286541

Hello,

It is possible with filter hook "cred_form_validate", for example:

add_filter('cred_form_validate', 'validate_address', 10, 2);
function validate_address( $error_fields, $form_data ) {
    list($fields,$errors)=$data; 
	if (in_array($form_data['id'], array(83))){ // replace 123 with your post form IDs
		$slug = 'wpcf-test-addr'; // replace test-addr with your custom address field slug
		if(!isset($_POST['toolset-extended-form-' . $slug]['latitude']) || empty($_POST['toolset-extended-form-' . $slug]['latitude'])){
			$errors['wpcf-test-addr'] = __('Please input a valid address');
		}
	}
    return array($fields,$errors);
}

More help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#2286561

Hi, thanks for the snippet.
Tested, but I get an error even if the address is legit.

#2286583
validate-address.jpg

I have tried above codes in my localhost, it works fine, please make sure you are using correct address field value, you can click the the link "Show/Hide coordinates", make sure you get the coordinates values, see my screenshot validate-address.JPG

#2286729

In my Cred module I do not have the option "Show/Hide Coordinates" front-end.
hidden link

and it generates the same error for the field "wpcf-address", with or without coordinates.

hidden link

So I checked backend the address field, and it generates the coordinates correctly, but I noticed that they don't reset if you switch to a non-existing address
hidden link

#2287295

The problem you mentioned above is abnormal, please check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

4) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL and form URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#2291345

Yes, there is a jscript error in console

hidden link

Tested with standard theme and only Toolset plugins + Woocommerce activated.

Any idea? Thanks

#2291431

The problem is abnormal, if there is any custom JS codes in that post form/page, please try to remove them, and test again.

If you still need more assistance for it, please provide a test site with the same problem, I need a live website to test and debug, thanks

The topic ‘[Closed] Validate Address Field’ is closed to new replies.