doubledee Posted April 18, 2012 Share Posted April 18, 2012 I can't seem to get htmlentities working in the code below... echo "<textarea id=\"question" . $questionNo . " name=\"qaArray[\"answerText\"]\" cols=\"60\" rows=\"2\">" . (isset($questionNo) ? "htmlentities($qaArray[\"answerText\"], ENT_QUOTES" : "") . "</textarea>"; I tried using the default single quotes around answerText but that doesn't, nor do my escaped double quotes. What is wrong? Thanks, Debbie Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/ Share on other sites More sharing options...
TimeBomb Posted April 18, 2012 Share Posted April 18, 2012 In this scenario, I highly suggest you use single quotes around strings instead of double quotes. Then you don't have to escape the double quotes. Why is the function htmlentities in quotes? You do not want to treat it as a string. Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338600 Share on other sites More sharing options...
samshel Posted April 18, 2012 Share Posted April 18, 2012 try this not tested... echo '<textarea id="question"'. $questionNo .'" name="'.$qaArray["answerText"].'" cols="60" rows="2">'.(isset($questionNo) ?htmlentities($qaArray["answerText"], ENT_QUOTES) : '') .'</textarea>'; Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338602 Share on other sites More sharing options...
Andy-H Posted April 18, 2012 Share Posted April 18, 2012 I can't seem to get htmlentities working in the code below... echo "<textarea id=\"question" . $questionNo . " name=\"qaArray[\"answerText\"]\" cols=\"60\" rows=\"2\">" . (isset($questionNo) ? "htmlentities($qaArray[\"answerText\"], ENT_QUOTES" : "") . "</textarea>"; I tried using the default single quotes around answerText but that doesn't, nor do my escaped double quotes. What is wrong? Thanks, Debbie Look at the syntax highlighting echo '<textarea id="question' . $questionNo . '" name="'. $qaArray['answerText'] .'" cols="60" rows="2">' . (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '') . '</textarea>'; Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338603 Share on other sites More sharing options...
doubledee Posted April 18, 2012 Author Share Posted April 18, 2012 How does this look... <?php foreach($thoughtsArray as $questionNo => $qaArray){ echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>'; echo '<textarea id="question' . $questionNo . '" name="' . $qaArray["answerText"] . '" cols="60" rows="2">'; echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : ''); echo '</textarea>'; } ?> It seems to run okay. Debbie Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338610 Share on other sites More sharing options...
Drummin Posted April 18, 2012 Share Posted April 18, 2012 Ya, seems to run fine, but what do I know. Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338612 Share on other sites More sharing options...
Drummin Posted April 18, 2012 Share Posted April 18, 2012 Actually, the textarea NAME should be the ID or are you using the actual question text as the identifier for the textarea on processing? <?php foreach($thoughtsArray as $questionNo => $qaArray){ echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>'; echo '<textarea id="question' . $questionNo . '" name="' . $qaArray['questionID'] . '" cols="60" rows="2">'; echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : ''); echo '</textarea>'; } ?> EDITED Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338617 Share on other sites More sharing options...
doubledee Posted April 18, 2012 Author Share Posted April 18, 2012 Ya, seems to run fine, but what do I know. You know a lot, and after I tweaked some things, it seems to be working. I would say it was a "group" effort... Debbie Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338619 Share on other sites More sharing options...
doubledee Posted April 18, 2012 Author Share Posted April 18, 2012 Actually, the textarea NAME should be the ID or are you using the actual question text as the identifier for the textarea on processing? <?php foreach($thoughtsArray as $questionNo => $qaArray){ echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . '</label>'; echo '<textarea id="question' . $questionNo . '" name="' . $qaArray['questionID'] . '" cols="60" rows="2">'; echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : ''); echo '</textarea>'; } ?> EDITED As I see it, this is how things should look... <?php foreach($thoughtsArray as $questionNo => $qaArray){ // Build Question. echo '<label for="question' . $questionNo . '">' . $questionNo . '.) ' . $qaArray['questionText'] . "\n"; // Build Answer. echo '<textarea id="question' . $questionNo . '" name="' . $qaArray["questionID"] . '" cols="60" rows="2">'; echo (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : ''); echo "</textarea>\n\n"; } ?> Yes, I changed name=$qaArray['question'] because that is what uniquely identifies a Question, and it is needed to write the Answer into the "answer" table... Debbie Link to comment https://forums.phpfreaks.com/topic/261205-problem-with-htmlentities/#findComment-1338621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.