Skip Navigation

[Resolved] Backslashes added on save in cred form

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 2 replies, has 2 voices.

Last updated by amandaD 1 year, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2603311
Screenshot 2023-05-05 132110.png

Every time my user save's their location in a CRED form, apostrophes get double escaped.
I have a location field. I expect to see: 68 O'Connell Street
Instead, I see: 68 O\\\\'Connell Street

More and more backslashes get added every time there is an edit.

The forums talk about similar problems in the CSS and JS sections, but those were apparently resolved 4 years ago?

#2603901

Hello,

I can duplicate the same problem, will escalate this issue.

Currently, please try to remove the extra Backslashes with cred_save_data actions, see below test site:
Login URL: hidden link

1) Dashboard-> Toolset-> Settings-> Custom codes:
hidden link

Add one item, with below codes:

add_action('cred_save_data', function($post_id, $form_data){
	if($form_data['id'] == 23){
      	$location = get_post_meta($post_id, 'wpcf-location', true);
      	update_post_meta($post_id, 'wpcf-location', stripcslashes($location));
    }
}, 99, 2);

Please replace 23 with your post form ID, replace "location" with your custom address field slug

2) Test it in frontend:
hidden link

It works fine.

More helps:
hidden link
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2603977

Thanks so much - that fixed my issue.