mert
mert

Reputation: 2002

php echo html without quotes and whitespace

I am trying to echo auto-generated html form elements, but the page always shows html code as text. When I check the output via Chrome, it shows generated form input with quotes and whitespaces. Here is what I have tried and results:

Here is code generates entire form

<form action="<?php echo url_for('/survey/submit?id='.$Survey->getId()) ?>" method="post">
    <ul>
    <?php foreach($Questions as $Question): ?>
        <li><?php echo $Question->questionHtml() ?></li>
    <?php endforeach; ?>
    </ul>
</form>

And here is a sample result:

"<li>
                                <input class="survey" size="40" type="text" name="Sample Survey[input_1]" id="Sample_Survey_input_1" />             </li>"

I tried htmlentities also.

echo htmlentities($Question->questionHtml())
"
                                &lt;input class=&quot;survey&quot; size=&quot;40&quot; type=&quot;text&quot; name=&quot;Sample Survey[input_1]&quot; id=&quot;Sample_Survey_input_1&quot; /&gt;             "

The problem is I couldn't get these generated form elements displayed on the page, but only plain text format of them.

Upvotes: 0

Views: 1209

Answers (2)

dotty
dotty

Reputation: 41433

If $Question->questionHtml() is echoing the correct HTML, then all you need is to use trim() to remove the whitespace.

Upvotes: 0

Galen
Galen

Reputation: 30170

If its showing the code you need to decode the html entities

echo html_entity_decode( $Question->questionHtml() );

http://www.php.net/manual/en/function.html-entity-decode.php

BUT

This shouldn't have to be done. The questionHtml() function should only turn the form values into their entities, not the entire form.

Upvotes: 1

Related Questions