domk Posted September 14, 2008 Share Posted September 14, 2008 hi there i just hit a problem with a very simple background: <? echo '<form method="post" action="?"> <textarea name="content" cols="50" rows="20" id="content">'.$_POST["content"].'</textarea> <input type="submit"> </form>'; ?> so what i'm doing here is calling the sent data via $_POST and by doing so i realized that if you enter an empty line on the beginning of your textarea text it will be vanished on the next call.... fun to watch when you enter five empty lines and by switching the submit query watch the text move up but really not meant to do that... i guess im overlooking something really simple here but i just cant get around it so any feedback is appreciated. thanks Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/ Share on other sites More sharing options...
domk Posted September 15, 2008 Author Share Posted September 15, 2008 anyone? ??? Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-641720 Share on other sites More sharing options...
genericnumber1 Posted September 15, 2008 Share Posted September 15, 2008 not sure. try echo '<form method="post" action="?"> <textarea name="content" cols="50" rows="20" id="content"> '.$_POST["content"].' </textarea> <input type="submit"> </form>'; Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-641737 Share on other sites More sharing options...
domk Posted September 15, 2008 Author Share Posted September 15, 2008 what am i missing here? your suggestion will add an empty line to the end instead of taking one from the top i guess i just have to replace the empty line with hidden placeholders like \n\r and convert them on display.... very strang though as it seems it is a bad bug any other ideas? Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-641937 Share on other sites More sharing options...
PFMaBiSmAd Posted September 15, 2008 Share Posted September 15, 2008 You would need to do it like this (tested) to avoid the problems - <?php echo '<form method="post" action="?"> <textarea name="content" cols="50" rows="20" id="content"> '.$_POST["content"].'</textarea> <input type="submit"> </form>'; ?> The w3.org specification does not state that a newline is required after the closing > of the <textarea tag, but both IE and FF take the first newline from any data you put there if the markup does not have a newline. Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-641944 Share on other sites More sharing options...
kenrbnsn Posted September 15, 2008 Share Posted September 15, 2008 When you redisplay text entered in a textarea you need to use the nl2br() function to change the newline characters to <br /> and a newline character. <?php echo '<form method="post" action=""> <textarea name="content" cols="50" rows="20" id="content">'.nl2br($_POST["content"]).'</textarea> <input type="submit"> </form>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-641946 Share on other sites More sharing options...
genericnumber1 Posted September 15, 2008 Share Posted September 15, 2008 When you redisplay text entered in a textarea you need to use the nl2br() function to change the newline characters to <br /> and a newline character. <?php echo '<form method="post" action=""> <textarea name="content" cols="50" rows="20" id="content">'.nl2br($_POST["content"]).'</textarea> <input type="submit"> </form>'; ?> Ken I'm not so sure about that one. Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-641996 Share on other sites More sharing options...
domk Posted September 16, 2008 Author Share Posted September 16, 2008 ok thanks for the answers <?php echo '<form method="post" action="?"> <textarea name="content" cols="50" rows="20" id="content"> '.$_POST["content"].'</textarea> <input type="submit"> </form>'; ?> that did the trick. thanks to PFMaBiSmAd for that one. <b>though</b> if you do not include a new line into your input it'll show a space(and add each time you submit) before your text much like: | text| instead of |text| but i can live with that as html does not display more then one space... i did actually play around with that a little but did not seem to find any reaseneble conclusion... very strange though as i think it is most definetely a bug... btw nl2br would print out a br tag for each new line which is visible in textareas so that'll defeat the purpose. good work!... and for me "back to work" Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-642600 Share on other sites More sharing options...
domk Posted September 16, 2008 Author Share Posted September 16, 2008 ... though that error is caused be my code sorting where i add a space up front to see clauses much like: if(something) { echo '<form method="post" action="?section=content&action='.trim($_GET['action']).'&do=save" onsubmit="return(check(this));"> <textarea name="content" cols="50" rows="20" id="content"> '.$mCont["content"].'</textarea> <input type="submit"> </form>"; } so i have to make it if(something) { echo '<form method="post" action="?section=content&action='.trim($_GET['action']).'&do=save" onsubmit="return(check(this));"> <textarea name="content" cols="50" rows="20" id="content"> '.$mCont["content"].'</textarea> <input type="submit"> </form>"; } and now it works like a charm p.s.: mark as SOLVED Link to comment https://forums.phpfreaks.com/topic/124226-php-loosing-empty-line-on-post-transfer/#findComment-642603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.