ianco Posted September 29, 2009 Share Posted September 29, 2009 HI all, I have a form with checkboxes and text boxes. When the check box is ticked some text appears which contains the variable text box. However I want to post html in the text box so it displays in the php output but unless i change everything first to eg. < then it doesnt appear. What i want is for the php to automatically change "<" to "<" etc. i've seen the htmlentities() but dont know where to put it. Any ideas? Here's the code <?PHP $ch1 = ' '; $ch2 = ' '; $ch3 = ' '; if (isset($_POST['Submit1'])) { if (isset($_POST['ch1'])) { $ch1 = $_POST['ch1']; if ($ch1 = 'net') { $ch1 = '<UL><br> <LI><br> <a href="' . $_POST['num'] . '.pdf">' . $_POST['det'] . '</a><br> </LI><br> <UL><br> <LI>(PDF format, <!-- #config SIZEFMT = "ABBREV" --><!--#fsize file="' . $_POST['num'] . '.pdf"--> KB)</LI><br> </UL><br> </UL><br> <br>'; } } etc. ?> <?PHP print $ch1; ?> --------------------- <Input type = 'Checkbox' Name ='ch1' value ="net" <?PHP print $ch1; ?> PDF<br> Details: <br> <input type="text" name="det" /><br> Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/ Share on other sites More sharing options...
jon23d Posted September 29, 2009 Share Posted September 29, 2009 I'm not 100% sure what you are asking, but perhaps this is what you need? : $my_string = <<<EOT <p>This is my return code $with_a_variable from {$_POST['var']}</p> EOT; $my_string = htmlentities($my_string, ENT_QUOTES); ENT_QUOTES causes both single and double quotes to be converted as well, I almost always use that. Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927162 Share on other sites More sharing options...
ianco Posted September 29, 2009 Author Share Posted September 29, 2009 So i should put $my_string = <<<EOT under $ch3 = ' '; and EOT before the last ?> ? What about $my_string = htmlentities($my_string, ENT_QUOTES);? Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927173 Share on other sites More sharing options...
jon23d Posted September 29, 2009 Share Posted September 29, 2009 <<<EOT && EOT; is heredoc sytax, its good for when your string is very complex. If its really messy, then consider using output buffering and require_once. Go read about htmlentities though, its super easy, it converts the characters that your browser views as html, to something that isn't parsed. http://us2.php.net/htmlentities Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927193 Share on other sites More sharing options...
ianco Posted September 29, 2009 Author Share Posted September 29, 2009 Ive tried ' . echo htmlentities($_POST['detcif'], ENT_QUOTES) . ' but i get Parse error: syntax error, unexpected T_ECHO in /www/uuuq.com/i/a/n/iancoates/htdocs/development/checkBoxes.php on line 59 i guess it's not in the write place Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927211 Share on other sites More sharing options...
jon23d Posted September 29, 2009 Share Posted September 29, 2009 Show the whole thing please Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927285 Share on other sites More sharing options...
ianco Posted September 30, 2009 Author Share Posted September 30, 2009 Here is my php file <?PHP $ch1 = ' '; $ch2 = ' '; $ch3 = ' '; if (isset($_POST['Submit1'])) { /* pdf */ if (isset($_POST['ch1'])) { $ch1 = $_POST['ch1']; if ($ch1 = 'net') { $ch1 = '<UL><br> <LI><br> <a href="' . $_POST['num'] . '.pdf">' . $_POST['det'] . '</a><br> </LI><br> <UL><br> <LI>(PDF format, <!-- #config SIZEFMT = "ABBREV" --><!--#fsize file="' . $_POST['num'] . '.pdf"--> KB)</LI><br> </UL><br> </UL><br> <br>'; } } if (isset($_POST['ch2'])) { $ch2 = $_POST['ch2']; if ($ch2 = 'word') { $ch2 = '<UL><br> <LI><br> <a href="' . $_POST['num'] . '.txt">' . $_POST['dettxt'] . '</a><br> </LI><br> <UL><br> <LI>(CIF format, <!-- #config SIZEFMT = "ABBREV" --><!--#fsize file="' . $_POST['num'] . '.txt"--> KB)</LI><br> </UL><br> </UL><br> <br>'; } } /* cif */ if (isset($_POST['ch3'])) { $ch3 = $_POST['ch3']; if ($ch3 = 'excel') { $ch3 = ' <UL><br> <LI><br> <a href="' . $_POST['num'] . '.cif">' . $_POST['detcif'] . '</a><br> </LI><br> <UL><br> <LI>(CIF format for CIF viewers, <!-- #config SIZEFMT = "ABBREV" --><!--#fsize file="' . $_POST['num'] . '.cif"--> KB)</LI><br> </UL><br> </UL><br> <br>'; } } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "hmpro6.dtd"><br> <HTML LANG="en"><br> <!-- This web site is © XXXXXXXXXXXXXX --><br> <!-- Site re-design 2002 by TechnoPhobia Ltd --><br> <HEAD><br> <TITLE>{Supplementary Data}</TITLE> <LINK REL="stylesheet" TYPE="text/css" NAME="style" HREF="/css/rsc2003.css"<br> MEDIA="screen"><br> <LINK REL="stylesheet" TYPE="text/css" HREF="/css/print2003.css"<br> MEDIA="print"><LINK REL="stylesheet" TYPE="text/css" NAME="style"<br> HREF="/css/xxxxxx.css" MEDIA="screen"> <br> </HEAD><br> <!--content start --><br> <br> <DIV CLASS="header"> Electronic Supplementary Information for <?php echo $_POST["jou"]; ?><br> <P>Paper <?php echo $_POST["num"]; ?></P></DIV> <br> <P>Click on a link to retrieve supplementary data submitted for this article:</P> <br> <br> <?PHP print $ch1; ?><br> <?PHP print $ch2; ?><br> <?PHP print $ch3; ?><br> <P><A HREF="http://dx.doi.org/10.1039/<?php echo $_POST["num"]; ?>">Back</A><br> </P><br> <br> <!-- content finish --><br> <!--footer finish--><br> </BODY><br> <br> </HTML><br> <br> Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927512 Share on other sites More sharing options...
jon23d Posted September 30, 2009 Share Posted September 30, 2009 Try something like this: Oh, and watch out for lines like: if ($ch2 = 'word') { <-- assignment in condition, it this what you really mean? This will ALWAYS evaluate to true. == is for comparing, = is for assigning, === is a strict comparison of obj type <? $page_template = <<<EOT <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "hmpro6.dtd"> <HTML LANG="en"> <!-- This web site is © XXXXXXXXXXXXXX --> <!-- Site re-design 2002 by TechnoPhobia Ltd --> <HEAD> <TITLE>{Supplementary Data}</TITLE> <LINK REL="stylesheet" TYPE="text/css" NAME="style" HREF="/css/rsc2003.css" MEDIA="screen"> <LINK REL="stylesheet" TYPE="text/css" HREF="/css/print2003.css" MEDIA="print"> <LINK REL="stylesheet" TYPE="text/css" NAME="style" HREF="/css/xxxxxx.css" MEDIA="screen"> </HEAD> <BODY> <!--content start --> <DIV CLASS="header"> Electronic Supplementary Information for {$_POST["jou"]} <P>Paper {$_POST["num"]}</P> </DIV> <P>Click on a link to retrieve supplementary data submitted for this article:</P> __my_stuff__ <P><A HREF="http://dx.doi.org/10.1039/{$_POST["num"]}">Back</A></P> <!-- content finish --> <!--footer finish--> </BODY> </HTML> EOT; /** * Get your string * * @param STRING $ext * @param STRING $num * @param STRING $det * * @return STRING */ function getMyThing($ext, $num, $det) { return "<UL> <LI> <a href='$num.$ext'>$det</a><br /> ($ext format, <!-- #config SIZEFMT = 'ABBREV' --><!--#fsize file='$num.$ext--> KB)</LI> </LI> </UL>"; } $contents = ""; if (isset($_POST['ch1']) && $_POST['ch1'] == 'net') $contents .= getMyThing('pdf', $_POST['num'], $_POST['det']); if (isset($_POST['ch2']) && $_POST['ch2'] == 'word') $contents .= getMyThing('cif', $_POST['num'], $_POST['dettxt']); if (isset($_POST['ch3']) && $_POST['ch3'] == 'net') $contents .= getMyThing('cif', $_POST['num'], $_POST['detcif']); echo htmlentities(str_replace("__my_stuff__", $contents, $page_template)); ?> Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927833 Share on other sites More sharing options...
ianco Posted September 30, 2009 Author Share Posted September 30, 2009 That kinda works but it removes my formatting <br> tags and changes some " marks. Can it just act on the $_POST['det'] bit? Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-927884 Share on other sites More sharing options...
jon23d Posted September 30, 2009 Share Posted September 30, 2009 echo htmlentities(str_replace("__my_stuff__", $contents, $page_template)); to: echo nl2br(htmlentities(str_replace("__my_stuff__", $contents, $page_template))); Will convert the line breaks to <br /> after changing the rest to entities, thus preserving your breaks. Link to comment https://forums.phpfreaks.com/topic/175959-more-form-bother/#findComment-928026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.