Sauter la navigation

[Résolu] Backslashes added on save in cred form

This support ticket is created Il y a 1 année et 8 mois. 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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par amandaD Il y a 1 année et 8 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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: lien caché

1) Dashboard-> Toolset-> Settings-> Custom codes:
lien caché

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:
lien caché

It works fine.

More helps:
lien caché
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2603977

Thanks so much - that fixed my issue.