worth2talk Posted April 21, 2007 Share Posted April 21, 2007 Hi PHP Freaks, I have been facing a problem with PHP forms. I have created a form to take inputs from users i.e. user comments and have to display it. But the comments user provide will always display in a signle line. For example, if user comment has couple of new line characters then all will come and display in a single line. main.php code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>PHP Test</title> <link href="test.css" type="text/css" media="screen" rel="stylesheet"> </head> <body> <form action="welcome.php" method="post"> <label for="user" >Name</label> <input type="text" name="user" value="" /><br /> <label for="emailaddress">Email Address:</label> <input type="text" name="emailaddress" value="" /> <font color="red">(will not be published)<br /> <label for=\"webaddress\">Web Address</label> <input type="text" name="url" value="" /><br /> <label for="comments">Comments:</label> <textarea name="comments"></textarea><br /> <label for="terms">Agree to Terms?</label> <input type="checkbox" name="terms" class="boxes" /><br /> <input type="hidden" name="pid" value='$pid' /><br /> <input type="submit" name="submitbutton" id="submitbutton" value="Submit" /> </form> </body> </html> comhandler.php <html> <body> <?php $userName = $_POST['user']; $userMail = $_POST['emailaddress']; $userUrl = $_POST['url']; $userComment = $_POST['comments']; echo "$userName"; echo "<br />"; echo "$userMail"; echo "<br />"; echo "$userUrl"; echo "<br />"; echo "$userComment"; echo "<br />"; echo "$magicString"; ?> </body> </html> Please guide me...as i m a newbie to PHP. Your quick response will be appreciated...!! Thanks in advance ..!! Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/ Share on other sites More sharing options...
Trium918 Posted April 21, 2007 Share Posted April 21, 2007 First you might want to modify your code by placing it inside [ code ] tags because no one wants to read that mess! <?php echo "$userName <br />"; echo "$userMail <br />"; echo "$userUrl <br />"; echo "$userComment <br />"; echo "$magicString"; // Or this echo "$userName \n"; echo "$userMail \n"; echo "$userUrl \n"; echo "$userComment \n"; echo "$magicString"; ?> Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234549 Share on other sites More sharing options...
worth2talk Posted April 21, 2007 Author Share Posted April 21, 2007 First of all sorry for messing up the code... i was not aware of that. Well, i dont want to add any newline character for displaying comment. I want to display as user entered.. For example, consider user provides comment as below: ---------------------------- Awesome.... wonderful Thanks ------------------------------ There are one newline after 1st sentence, 3 newlines after 2nd sentence... With my original code, the above comment will display everything in a single line as: Awesome.... wonderful Thanks but i want to output in the same input format... hope u will get this. Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234553 Share on other sites More sharing options...
Trium918 Posted April 21, 2007 Share Posted April 21, 2007 Something like this? http://www.mylabserver.com/242/morris/projects/project4.php Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234554 Share on other sites More sharing options...
worth2talk Posted April 21, 2007 Author Share Posted April 21, 2007 yes, thats cool.. can u guide me how to do it....?? Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234556 Share on other sites More sharing options...
Trium918 Posted April 21, 2007 Share Posted April 21, 2007 What are you writing it to? File or database? Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234557 Share on other sites More sharing options...
worth2talk Posted April 21, 2007 Author Share Posted April 21, 2007 I am writting it to MYSQL Database. But even if i display using echo, its not displaying...!! Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234558 Share on other sites More sharing options...
worth2talk Posted April 21, 2007 Author Share Posted April 21, 2007 I can use nl2br() function and it will work. But another problem is to filtered the user code provided as a part of comment. For example, someone tries to provide a spam input as <script type='text/javascript'> window.location = 'http://www.spamsite.com/' </script>'"; to avoid this i have to used below code before displaying comment $userFilteredComment = htmlentities($userComment); so how to display newline now ?? Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234560 Share on other sites More sharing options...
worth2talk Posted April 21, 2007 Author Share Posted April 21, 2007 i found a way to display this... $userFilteredComment = htmlentities($userComment); $userFilteredComment = nl2br($userFilteredComment); but now the issue is, MYSQL query got failed when i am trying to write this '$userFilteredComment' in table. Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234564 Share on other sites More sharing options...
worth2talk Posted April 21, 2007 Author Share Posted April 21, 2007 This disappoint me a lot that there is not a single PHP guru in this forum.... who can help me resolving my problem.... Link to comment https://forums.phpfreaks.com/topic/47994-help-how-to-display-comment-field/#findComment-234616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.