Skip Navigation

[Resolved] Javascript modified when saving CRED form

This thread is resolved. Here is a description of the problem and solution.

Problem:
Enable CRED to save HTML

add_filter('wp_kses_allowed_html', 'add_tag_func');
function add_tag_func($tags){
    $tags['option']['value'] = 1;
    return $tags;
}

Relevant Documentation:
http://codex.wordpress.org/Function_Reference/wp_kses_allowed_html

100% of people find this useful.

This support ticket is created 8 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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by samB-3 8 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#364800

I am trying to add a place holder to my select field in a CRED form. The following code:

jQuery("select[name='category[]']").prepend('<option value="selectCategory">-- Select Category --</option>');
jQuery("select[name='category[]']")[0].selectedIndex = 0;

jQuery("select[name='country[]']").prepend('<option value="selectCountry">-- Select Country --</option>');
jQuery("select[name='country[]']")[0].selectedIndex = 0;

But when I save the CRED form it gets changed to this:

jQuery("select[name='category[]']").prepend('-- Select Category --');
jQuery("select[name='category[]']")[0].selectedIndex = 0;
 
jQuery("select[name='country[]']").prepend('-- Select Country --');
jQuery("select[name='country[]']")[0].selectedIndex = 0;

This works fine in CRED 1.2.5 however every version since then has had the issue described below. I even posted before and was sent a dev version that fixed it but it doesn't seem like it was ever incorporated into a final version as I just tried upgrading to 1.4.2.2 and it has the same issue. Here's my previous post:

https://toolset.com/forums/topic/javascript-modified-when-saving-cred-form/

Thanks for helping me figure this out.

#364903

Dear sam,

Thanks for the details, CRED is using wordpress function wp_kses_allowed_html to setup allowed tags and attributes, in your case, HTML tag "options" is not in the white list, please try add below codes in your theme/functions.php:

add_filter('wp_kses_allowed_html', 'add_tag_func');
function add_tag_func($tags){
	$tags['option']['value'] = 1;
	return $tags;
}

More help:
http://codex.wordpress.org/Function_Reference/wp_kses_allowed_html

#365468

Thanks, Luoy. Spot on as usual.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.