yami007 Posted October 10, 2009 Share Posted October 10, 2009 here's the code so far : <form action="" method="post"> <textarea cols="80" rows="10" name="note" wrap="cirtual"><?php @ReadFile("guestbook.php"); ?></textarea> </form> the problem is when there's a button inside the html, like <input type="submit" value="submit" /> it leaves the textarea, what should i do to escape this?? Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/ Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 what do you mean by "leaves the text area"? And why would you have a button inside textarea tags? Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934289 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 what do you mean by "leaves the text area"? And why would you have a button inside textarea tags? leaves the text area, i'm trying to read the whole file inside the textarea, but when there's a submit button, the text area stops, and the button is shown in normal, see please the attachment. i want to hav it inside the textarea because i'm trying to edit that file : guestbook ^^ [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934300 Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 hmm maybe you need htmlentities Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934303 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 hmm maybe you need htmlentities it's not working, the same issue again Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934316 Share on other sites More sharing options...
Andy-H Posted October 10, 2009 Share Posted October 10, 2009 try using htmlentities() with the ENT_QUOTES flag. htmlentities(ReadFile("guestbook.php"), ENT_QUOTES)); Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934320 Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 can you post how you tried to use it? Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934323 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 this is how i did it : <textarea cols="80" rows="10" name="note" wrap="cirtual"> <?php htmlentities(ReadFile("guestbook.php"), ENT_QUOTES); ?> </textarea> and it's not working !! Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934338 Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 how about trying htmlentities + file_get_contents instead of readfile Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934352 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 oh i get it now, it's not the input submit which leaves, it's the textarea inside textarea which is the problem Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934362 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 well the problem is in the textarea when html finds </textarea>, it closes it and the rest is lost. so how can i avoid this? Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934444 Share on other sites More sharing options...
Andy-H Posted October 10, 2009 Share Posted October 10, 2009 $text = ReadFile("guestbook.php"); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); <form action="" method="post"> <textarea cols="80" rows="10" name="note" wrap="cirtual"> <?php echo stripslashes(htmlentities($text, ENT_QUOTES)); ?> </textarea> </form> Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934448 Share on other sites More sharing options...
newbtophp Posted October 10, 2009 Share Posted October 10, 2009 This is a better way: <?php if($_POST['Submit']){ $open = fopen("guestbook.php","w+"); $text = $_POST['update']; fwrite($open, urldecode($text)); fclose($open); echo "Updated"; }else{ $file = file("guestbook.php"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" id=\"phpCode\"cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "</br><input name=\"Submit\" type=\"submit\" value=\"Update\" onClick=\"document.getElementById('phpCode').value = escape(document.getElementById('phpCode').value)\"/>\n </form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934449 Share on other sites More sharing options...
Andy-H Posted October 10, 2009 Share Posted October 10, 2009 Is it? I was under the impression javascript can be disabled and should not be used to escape data... Also "</br>" ??? Also, why are you only showing the form and escaping the data once the form is submitted. Escaping onclick of a button will not change the way it is displayed... Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934457 Share on other sites More sharing options...
newbtophp Posted October 10, 2009 Share Posted October 10, 2009 Is it? I was under the impression javascript can be disabled and should not be used to escape data... Also "</br>" ??? Also, why are you only showing the form and escaping the data once the form is submitted. Escaping onclick of a button will not change the way it is displayed... If i didnt escape it, when i go back to the editor the file will not be the same as the original. PS: This is a personal opinion. </br> is just a habiit, he can remove if he'd like too. However im new to php so looking forward to suggestions etc. Just thought I should try and contribute. Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934460 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 both are not working This is a better way: well the second is still giving me the same problem the first one, not even working :s Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934461 Share on other sites More sharing options...
Andy-H Posted October 10, 2009 Share Posted October 10, 2009 Can you post a link to the page where the error occurs? Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934463 Share on other sites More sharing options...
yami007 Posted October 10, 2009 Author Share Posted October 10, 2009 $text = ReadFile("guestbook.php"); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); <form action="" method="post"> <textarea cols="80" rows="10" name="note" wrap="cirtual"> <?php echo stripslashes(htmlentities($text, ENT_QUOTES)); ?> </textarea> </form> thanks it ddnt work, but i rewrote your code and did this : <?php $text = file_get_contents("guestbook.php"); ?> <form action="" method="post"> <textarea cols="80" rows="10" name="note" wrap="cirtual"> <?php echo stripslashes(htmlentities($text, ENT_QUOTES)); ?> </textarea> </form> so file_get_contents was the right option ^^ PS : i had to remove those lines : $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); they're not necessary since file_get_contents do the job.. Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934467 Share on other sites More sharing options...
newbtophp Posted October 10, 2009 Share Posted October 10, 2009 $text = ReadFile("guestbook.php"); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); <form action="" method="post"> <textarea cols="80" rows="10" name="note" wrap="cirtual"> <?php echo stripslashes(htmlentities($text, ENT_QUOTES)); ?> </textarea> </form> thanks it ddnt work, but i rewrote your code and did this : <?php $text = file_get_contents("guestbook.php"); ?> <form action="" method="post"> <textarea cols="80" rows="10" name="note" wrap="cirtual"> <?php echo stripslashes(htmlentities($text, ENT_QUOTES)); ?> </textarea> </form> so file_get_contents was the right option ^^ PS : i had to remove those lines : $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); they're not necessary since file_get_contents do the job.. Then you wernt trying to edit the php source?, you wanted to edit the html? Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934468 Share on other sites More sharing options...
mikesta707 Posted October 10, 2009 Share Posted October 10, 2009 $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); doing this is pointless, as htmlentities does this, and more Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934479 Share on other sites More sharing options...
yami007 Posted October 11, 2009 Author Share Posted October 11, 2009 Then you wernt trying to edit the php source?, you wanted to edit the html? well i wanted to edit the whole file, not only php!! Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934835 Share on other sites More sharing options...
yami007 Posted October 11, 2009 Author Share Posted October 11, 2009 $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); doing this is pointless, as htmlentities does this, and more i see, thanks Quote Link to comment https://forums.phpfreaks.com/topic/177198-solved-problem-with-my-first-basic-editor/#findComment-934838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.