Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter IvanRF

    (@ivanrf)

    Ov3rfly

    (@ov3rfly)

    You could use the wpcf7_form_elements filter to change the generated html before it is printed.

    You should be familiar with PHP and regex. Won’t give further support besides this example. No warranties of any kind.

    Your above example html result, & replaced with &_ to bypass forum formatting:

    <span class=”wpcf7-form-control-wrap your-sports”><span class=”wpcf7-form-control wpcf7-radio”><span class=”wpcf7-list-item first”><input type=”radio” name=”your-sports” value=”Football &_lt;b&_gt;$25&_lt;/b&_gt;” />&_nbsp;<span class=”wpcf7-list-item-label”>Football &_lt;b&_gt;$25&_lt;/b&_gt;</span></span><span class=”wpcf7-list-item last”><input type=”radio” name=”your-sports” value=”Tennis &_lt;b&_gt;$50&_lt;/b&_gt;” />&_nbsp;<span class=”wpcf7-list-item-label”>Tennis &_lt;b&_gt;$50&_lt;/b&_gt;</span></span></span></span>

    A filter which does some decoding before html is printed:

    function my_wpcf7_form_elements( $html ) {
    	// <input type="radio" name="your-sports" value="Football &_lt;b&_gt;$25&_lt;/b&_gt;" />
    	// <input type="radio" name="your-sports" value="Football &_lt;b&_gt;$25&_lt;/b&_gt;" checked=.. />
    	$html = preg_replace_callback(
    		'/\<input type="radio" name="(.*?)" value="(.*?)"[^>]*\>/i',
    		function ($arr) {
    			return str_replace(
    				'value="' . $arr[2] . '"',
    				'value="' . esc_attr( strip_tags( html_entity_decode( $arr[2] ) ) ) . '"',
    				$arr[0]
    			);
    		},
    		$html
    	);
    	// <span class="wpcf7-list-item-label">Tennis &_lt;b&_gt;$50&_lt;/b&_gt;</span>
    	$html = preg_replace_callback(
    		'/\<span class="wpcf7\-list\-item\-label"\>(.*?)\<\/span\>/i',
    		function ($arr) {
    			return str_replace(
    				$arr[1],
    				html_entity_decode( $arr[1] ),
    				$arr[0]
    			);
    		},
    		$html
    	);
    	return $html;
    }
    add_filter( 'wpcf7_form_elements', 'my_wpcf7_form_elements', 10, 1 );

    Your example html output with the filter in place:

    <span class=”wpcf7-form-control-wrap your-sports”><span class=”wpcf7-form-control wpcf7-radio”><span class=”wpcf7-list-item first”><input type=”radio” name=”your-sports” value=”Football $25″ />?<span class=”wpcf7-list-item-label”>Football <b>$25</b></span></span><span class=”wpcf7-list-item last”><input type=”radio” name=”your-sports” value=”Tennis $50″ />?<span class=”wpcf7-list-item-label”>Tennis <b>$50</b></span></span></span></span>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use HTML inside radio buttons text’ is closed to new replies.