I'm using the Webform module to create a form and all is going well, but it's creating the HTML for the description field even if there is no description (help text) present. Here's what's getting displayed:

<div class="description">
<p/>
</div>

The problem is that the "p" tag is throwing up some CSS that I don't need in this case. Is there a way to only print the HTML for the description if the description field has actual data in it? Something like:

<?php if ($description): ?>
    <div class="description"><?php print $description ?></div>
<?php endif;?>

I have no idea if $description is a valid variable or not -- this was just for example.

Comments

quicksketch’s picture

Category: bug » support

Webform will not print out the description if it is truly empty. The problem you're having looks like it's caused by having a WYSIWYG editor enabled, which is inserting an empty <p></p> tag into the description textarea.

Saoirse1916’s picture

I'm not using a WYSIWYG editor but I am using BBCode -- would that have anything to do with it?

quicksketch’s picture

Oh, hmm. I'm not familiar enough with BBCode to know if it might be having that effect. I don't think it should make a difference, since the description field isn't run through the normal filtering system in which BBCode has control.

Saoirse1916’s picture

That's what I thought. If webform does do the if/then code that I mentioned in my initial post, where in the module is it? I've looked for anything to do with that description field and haven't found much relevant code.

Saoirse1916’s picture

Can anyone point me to the code that controls the display of the description field?

quicksketch’s picture

Status: Active » Closed (fixed)

All of the descriptions are added within each individual component.inc file. Usually the line looks like this:

    '#description'   => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],

In most cases the description is inserted directly into the element, meaning that the <p></p> tags must already be inside the description at the point where they are set. I'm closing this issue directly considering it is so old.