Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Enter key Wrecks everything!

    So I'm writing webapp wiht php, you can post something on a page and only edit it by pressing that comment,(Comments are stored in .txt files) but as soon as you press your enter key in your post, you can no longer edit it and it's totally wrecked.. How can an enter key wreck the code? I'm thinking about a rewrite but if someone knows how to fix this, please?

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Pressing an enter key... What you mean while you have a cursor in a text field? Text box? No cursor at all? Is the form submitting prematurely?

    This sounds like a potential javascript problem but given the lack of information you've supplied there really isn't a great deal with can do to help you.

    Also storing stuff in text files is such a bad idea. It's old school, insecure, sloppy, messy, easy to corrupt etc. Learn to use a database. I know they sound boring and complicated but trust me they make life so much easier!
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    Junsee
    Guest
    how can you expect us to know what you are talking about without giving us the code?

    maybe nl2br() ?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yeah, you'll need a little more description of the problem since:
    Enter key Wrecks everything!
    Is quite impossible with a server side language.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    whats the bet that it has something to do with \r\n ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Web app;
    http://picturemevisuals.nl/dag/test.php

    try creating a post, hit your enter, and submit it. by clicking on a post you can edit it. (at least if you don't hit your enter key..) Try it!

    Here's the code

    boek.php
    Code:
    <html>
    <head>
    <script language="javascript" type="text/javascript">
    
    function hide_m(){
    	document.getElementById('man').style.visibility="hidden";
    	document.getElementById('woman').style.visibility="visible";}
    
    function hide_v(){
    	document.getElementById('woman').style.visibility="hidden";
    	document.getElementById('man').style.visibility="visible";}
    
    function reset(){
    	document.getElementById('hidden').value ="0";
    	document.getElementById('cijfer').value ="";}
    </script>
    
    <style type="text/css">
    body
    {
    	font-family:Arial, Helvetica, sans-serif;
    	background-color:#333;
    	font-size:12px;
    }
    div#Scroll
    {
    	top:0px;
        bottom:0px;
    	width:auto;
    	overflow:scroll;
    	background-color:#666;
    	left:200px;
        position:absolute;
    }
    
    div#process
    {	top:0px;
        bottom:0px;
        width:300px;
        background-color:#333;
        left:500px;
        position:absolute;
    }
    
    div#m
    {
    	background-image:url(characterm.png);
    	padding-right:70px;
    	padding-top:5px;
    	padding-bottom:5px;
    	padding-left:5px;
    	overflow:auto;
    }
    div#v
    {
    	background-image:url(characters.png);
    	padding-right:70px;
    	padding-top:5px;
    	padding-bottom:5px;
    	padding-left:5px;
    	overflow:auto;
    }
    textarea#text_post
    {
    	width:300px;
    	height:100px;
    	left:0px;
    	background-color:#333;
    	color:#666;
    	
    }
    
    table#pick
    {
    	color:#333;
    }
    
    form#post
    {
    	color:#CCC;
    }
    
    
    </style>
    
    
    
    </head>
    <body>
    
    <div id="Scroll">
    
    <?php include('div.php'); ?>
    
    </div>
    
    <div id="process">
        	<form id="post"  name="form" method="post" action="process.php">
            Voer dagnummer in 
            <select style="visibility:visible;" id="woman" name="text_woman">
            <?php  
    		$tel=1;
    		
    		while($tel<=365){
    				if (file_exists($tel.' '.'v'.'.txt')){echo "<option disabled='disabled' value='$tel'>$tel</option>";$tel++;}
    				else{echo"<option  onChange='reset()' value='$tel'>$tel</option>";$tel++;}
    		}
    		?>
            </select>
            <select style="visibility:hidden;" id="man" name="text_man">
            <?php
    		$mtel=1;
    		while($mtel<=365){
    				if (file_exists($mtel.' '.'m'.'.txt')){echo "<option disabled='disabled' value='$mtel'>$mtel</option>";$mtel++;}
    				else{echo"<option onChange='reset()' value='$mtel'>$mtel</option>";$mtel++;}
    		}
    		?>
            </select>
            	
            <br>
            <textarea rows="7" cols="39" type="text" id="text_post" name="text_post"></textarea>
            
            <br>
            <select id="hidden" style="visibility:hidden; position:absolute;" name="hidden">
            	<option value="0"></option>
                <option value="1"></option>
            </select>
            <textarea name="cijfer" id="cijfer" style="visibility:hidden; position:absolute;"></textarea>
            <input type="radio" id="myRadio" onClick="hide_m()" name="myRadio" value="1" checked/> Lisanne
            <input type="radio" id="mmyRadio" onClick="hide_v()"name="myRadio" value="2" /> Tristan
            <input type="submit"/>
            
            
            </form>
            <?php $t=date("z");?>
            <a style="color:#CCC;">
            Stap 1.<br/>
            Selecter je naam.<br/><br/>
            Stap 2.<br/>
            Selecteer dag-nummer.<br/><br/>
            Stap 3.<br/>
            Plaats gewenste text in textvlak.<br/><br/>
            Stap 4.<br/>
            Klik op "Verzenden"<br/>
            <br/><br/>
            Om aan te passen:<br/>
            Stap 1.<br/>
            Klik op een bestaande post.<br/><br/>
            Stap 2.<br/>
            Pas de text in het textvlak aan.<br/><br/>
            Stap 3.<br/>
            Klik op "verzenden".
    		<br/><br/>
            Today is day <a style="color:red"><?php echo $t; ?></a>.</a>
            <br>
            <?php include('date.php'); ?>
            
        </div>
        
    
    </body>
    </html>
    process.php
    Code:
    <?php
    header("location:test.php");
    $post = $_POST['text_post'];
    $date = $_POST['text_woman'];
    $datem= $_POST['text_man'];
    $dateh= $_POST['hidden'];
    $datec= $_POST['cijfer'];
    $myRadio = intval($_POST['myRadio']);
    $t=date("z");
    $z=($post);
    
    $y=($post);
    echo "test ";
    
    if ($myRadio === 2){
    	if ($dateh === '0'){ 
     		if($datem <366){
    		  global $y,$datem;
    		  $n=$datem." m.txt";
    		  $v=fopen($n,'w+');
    		  fwrite($v,$y);
    		  fclose($v);
    	  	}
    	  }
    	  else{
    		  	global $y,$datec;
    		  	$m=$datec." m.txt";
    		  	$v=fopen($m,'w+');
    		  	fwrite($v,$y);
    		  	fclose($v);
    	  	}
    	}
    else{
    	if ($dateh === '0'){ 
     		if($date <366){
    		  global $y,$date;
    		  $e=$date." v.txt";
    		  $v=fopen($e,'w+');
    		  fwrite($v,$y);
    		  fclose($v);
    	  	}
    	  }
    	  else{
    		  	global $y,$datec;
    		  	$c=$datec." v.txt";
    		  	$v=fopen($c,'w+');
    		  	fwrite($v,$y);
    		  	fclose($v);
    	  	}
    	}
    
      
    
      
    echo $datem." datem ".$date." date ". $dateh." dateh ".$datec." datec ";
    
    
    
    
    
    
    
    ?>
    div.php
    Code:
    <?php
    $count=1;
    
    
    while($count<=365){
    if (file_exists($count.' '.'v'.'.txt')){
    	echo "Gepost op dag ".$count." van het jaar.";
    	$file = fopen($count.' '.'v'.'.txt', 'r');
    	$text = fread($file, filesize($count.' '.'v'.'.txt'));
    	echo "
    		<script language='javascript' type='text/javascript'>
    			function writeto$count(){
    				document.getElementById( 'text_post' ).value = '$text';
    				document.getElementById( 'woman' ).value = '$count';
    				document.getElementById('myRadio').checked = true;
    				document.getElementById('mmyRadio').checked = false;
    				document.getElementById('man').style.visibility='hidden';
    				document.getElementById('woman').style.visibility='visible';
    				document.getElementById('hidden').value ='1';
    				document.getElementById('cijfer').value ='$count';}
    		</script>";
    	fclose($file);
    	echo "<div id='v' onclick='writeto".$count."()' style='background-color:; word-wrap: break-word; width:225px; height:90px;'>".$text."</div>";
    	
    	
    	
    	if (file_exists($count.' '.'m'.'.txt')){
    		$filem = fopen($count.' '.'m'.'.txt', 'r');
    		$text = fread($filem, filesize($count.' '.'m'.'.txt'));
    		echo "
    			<script language='javascript' type='text/javascript'>
    				function writetom$count(){
    					document.getElementById( 'text_post' ).value = '$text';
    					document.getElementById( 'man' ).value = '$count';
    					document.getElementById('myRadio').checked = false;
    					document.getElementById('mmyRadio').checked = true;
    					document.getElementById('woman').style.visibility='hidden';
    					document.getElementById('man').style.visibility='visible';
    					document.getElementById('hidden').value ='1';
    					document.getElementById('cijfer').value ='$count';}
    			</script>";
    		fclose($filem);
    		echo "<div id='m' onclick='writetom".$count."()' style='background-color:; word-wrap: break-word; width:225px; 			height:90px;'>".$text."</div>";
    	
    	echo "<hr size=1>";}
    	
    	else{echo "<hr size=1>";}
    		$count++;
    }
    	
    	
    
    
    else{
    	if (file_exists($count.' '.'m'.'.txt')){
    		echo "Gepost op dag ".$count." van het jaar.";
    		$filem = fopen($count.' '.'m'.'.txt', 'r');
    		$text = fread($filem, filesize($count.' '.'m'.'.txt'));
    		echo "
    			<script language='javascript' type='text/javascript'>
    				function writetom$count(){
    					document.getElementById( 'text_post' ).value = '$text';
    					document.getElementById( 'man' ).value = '$count';
    					document.getElementById('myRadio').checked = false;
    					document.getElementById('mmyRadio').checked = true;
    					document.getElementById('woman').style.visibility='hidden';
    					document.getElementById('man').style.visibility='visible';
    					document.getElementById('hidden').value ='1';
    					document.getElementById('cijfer').value ='$count';}
    			</script>";
    		fclose($filem);
    		echo "<div id='m' onclick='writetom".$count."()' style='background-color:; word-wrap: break-word; width:225px; height:90px;'>".$text."</div>";
    	
    	$count++;
    	echo "<hr size=1>";
    	}
    	
    	else{
    	$count++;
    	}
    }
    }
    
    ?>
    </div>
    </body>
    </html>

  • #7
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, there is some JS involved

  • #8
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just tried to post the whole code but it said i have to wait for it to get verified..

    But here is the app itself;
    http://picturemevisuals.nl/dag/test.php

    Sorry for the strange language, it's dutch

  • #9
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Forum keep you waiting, I just posted the full code and website link.. but it's gonna take some time I guess..

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Trisy123 View Post
    yes, there is some JS involved
    I see you clearly love to give us a full description of the behaviour of your webpage / form.

    I have explicitly asked you to describe the behaviour of your problem but you have refused to do so.

    If you do not wish to describe your problem then I do not wish to help you
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #11
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    I see you clearly love to give us a full description of the behaviour of your webpage / form.

    I have explicitly asked you to describe the behaviour of your problem but you have refused to do so.

    If you do not wish to describe your problem then I do not wish to help you
    Hey, I'm new on this forum. And so far it's not working in my favor. I cannot edit anything. I posted a full description, my code and a link to the app. But your mods have to confirm it. (Why?!) the post about JS being in it was a reply, but the forum was like "hey, you want to reply? Well lets just make it look like a post." I'm doing my best okay? I'll try to describe it without code or a link;

    I have a web app, every day you can post a little something. (by filling in a text area and submitting it) but as soon as you hit the enter key in your textarea, it will (I think) break the value of the textarea when it's taken from a .txt to the website. Normally it will allow you to click that post and edit it again, but when the value contains that enter(which is not a <br> or anything related, just a new line like you see it in your notepad) you can no longer edit it.. And I can't seem to find the problem :[

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Trisy123 View Post
    but as soon as you hit the enter key in your textarea, it will (I think) break the value of the textarea when it's taken from a .txt to the website. Normally it will allow you to click that post and edit it again, but when the value contains that enter(which is not a <br> or anything related, just a new line like you see it in your notepad) you can no longer edit it.. And I can't seem to find the problem :[
    Far more helpful.

    Enter in php is different on windows and unix/linux systems. On the latter it's \n but on windows its \r\n (you can't see these - just like the space character but they are there).

    I suspect the code you're using is possibly only reading the file UPTO this point and ignoring the rest of the file.

    Really though your description still isn't great so I'm going to ask you to take some screenshots step by step and then use postimage.org to host them and show us?

    As for the mods, we've had a LOT of spammers and thus the mods have had to tighten up on new posters especially anything that contains BB tags.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #13
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Far more helpful.

    Enter in php is different on windows and unix/linux systems. On the latter it's \n but on windows its \r\n (you can't see these - just like the space character but they are there).

    I suspect the code you're using is possibly only reading the file UPTO this point and ignoring the rest of the file.

    Really though your description still isn't great so I'm going to ask you to take some screenshots step by step and then use postimage.org to host them and show us?

    As for the mods, we've had a LOT of spammers and thus the mods have had to tighten up on new posters especially anything that contains BB tags.
    As I noticed, it seems to be a JS problem indeed..
    When you click on a post, everything at the right will change to the right settings and add the existing post. But it seems that this line break is breaking that function. I'm not soo good at explaining, but with this screencap it must be pretty clear.

  • #14
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I made a screencap with some additional comments and it's being verified by the mods I guess, so soon there will be a screencap and so more details. I hope it gets trough soon..

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Trisy123 View Post
    I made a screencap
    I think we may need more than one
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •