Hi Carl,
Thanks for the comment. I hear you that it doesn't support it (via admin console) but it does (inadvertently?) support it via hooks. Below is a function I'm using to present a list of categories and their descriptions to users, but the HTML I am using for formatting gets displayed on the page instead of affecting the formatting of the content as I intended.
I hacked your plugin to make it work (i.e. I only removed the call to esc_html()) and it displays as I want it to but I don't like hacking someone else's code that will be upgraded in the future.
Here's a simple thing; could you check a value in the field array and not escape the HTML if it exists and is false? (i.e. $field['esc_html']==false.) That way I can create forward compatible code....
Thanks for considering.
add_filter('gform_pre_render_2', 'populate_dropdown');
function populate_dropdown($form){
$args = array(
'hide_empty' => false,
'exclude' => 1, // 1 = Uncategorized
);
$categories = get_categories($args);
//Creating drop down item array.
$items = array();
//Adding post titles to the items array
foreach($categories as $category) {
$items[] = array(
'value' => $category->slug,
'text' => '<span class="category-name">' .
$category->name .
'</span>: <div class="category-description">' .
$category->category_description .
'</span>',
'isSelected' => false
);
}
$items[] = array(
'value' => 'other',
'text'=>'<span class="category-name">Other</span>: '
. '<div class="category-description">'
. 'Something else? Tell us below.'
. '</span>',
'isSelected' => false
);
foreach($form["fields"] as &$field)
if(element_equals($field,'inputName','categories')) {
$field["choices"] = $items;
break;
}
return $form;
}
Posted 14 years ago on Monday February 15, 2010 |
Permalink