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())
"
<input class="survey" size="40" type="text" name="Sample Survey[input_1]" id="Sample_Survey_input_1" /> "
The problem is I couldn't get these generated form elements displayed on the page, but only plain text format of them.
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.
如果$Question->questionHtml()
回显了正确的HTML,那么您所需要做的就是使用trim()
删除空白。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.