CodeIgniter Forums
textarea duplicates line breaks - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: textarea duplicates line breaks (/showthread.php?tid=38254)

Pages: 1 2


textarea duplicates line breaks - El Forum - 02-03-2011

[eluser]Unknown[/eluser]
Hi!

I started a new project on CI 2.0 and I made a simple form which contains a textarea and a submit button. When I submit the form the CI duplicates every line breaks of the textarea.

Here's my view file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html &gt;

&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;title&gt;title&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;form action="http://localhost/test/test" method="post" accept-charset="utf-8"&gt;
        &lt;textarea rows="10" cols="50" id="text" name="text" class="text"&gt;&lt;?php echo $text; ?&gt;&lt;/textarea&gt;
        &lt;input type="submit" name="submit" value="submit" class="" /&gt;
    &lt;/form&gt;
&lt;/body&gt;


In the controller I just simply use var_dump to display the submitted result and I send back the text to the view file:

Code:
echo "<pre>";
var_dump($_POST['text']);
echo "</pre>";

$this->data['text'] = $_POST['text'];
$this->load->view('test', $this->data);

I write "a[enter]b" in the textarea and this is the var_dump result after the first submit (a plus empty line created between the two characters):
Code:
string 'a


b' (length=5)


When I submit the form once again the distance increses between the two character. I get this:
Code:
string 'a





b' (length=8)


First 1 empty line inserted, but later 3, 7, 15, 31 (and so on...) created after every line breaks.
This happens on CI 2.0.0. but this exact code perfectly works on CI 1.7.3. (I use Win7 and WampServer.)
Is this a bug? What should I do now to fix this?


textarea duplicates line breaks - El Forum - 02-09-2011

[eluser]tilmankoester[/eluser]
Same thing happens to me.
Haven't had time to look into it yet, so if someone has an answer, please help out.


textarea duplicates line breaks - El Forum - 02-10-2011

[eluser]lontong balap[/eluser]
I found something, check this Link


textarea duplicates line breaks - El Forum - 02-21-2011

[eluser]Future Webs[/eluser]
just joining the party waiting for a fix


textarea duplicates line breaks - El Forum - 02-22-2011

[eluser]lontong balap[/eluser]
Write new file my_input.php then save in your application/core folder.
Here's the code :
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input Extends CI_Input {
    public function __construct()
    {
        if (PHP_EOL == "\r\n"){
            $this->_standardize_newlines = FALSE;
            log_message('debug', 'Windows server: standardize newlines disabled.');
        }

    parent::__construct();

    }

}



textarea duplicates line breaks - El Forum - 03-07-2011

[eluser]Swedie[/eluser]
I'd also like to bump this to get the attention of the CI developers.

This must be fixed in new release of CI.


textarea duplicates line breaks - El Forum - 03-22-2011

[eluser]Unknown[/eluser]
[quote author="yusuf.ty" date="1298379044"]Write new file my_input.php then save in your application/core folder.
Here's the code :
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input Extends CI_Input {
    public function __construct()
    {
        if (PHP_EOL == "\r\n"){
            $this->_standardize_newlines = FALSE;
            log_message('debug', 'Windows server: standardize newlines disabled.');
        }

    parent::__construct();

    }

}
[/quote]

Thanks a lot for the fix.. Works fine..


textarea duplicates line breaks - El Forum - 04-06-2011

[eluser]mikkelz[/eluser]
Thank you, yusuf.ty

Just what I was looking for!


textarea duplicates line breaks - El Forum - 04-06-2011

[eluser]JuanitoDelCielo[/eluser]
https://bitbucket.org/ellislab/codeigniter-reactor/changeset/c1584c431c64


textarea duplicates line breaks - El Forum - 04-07-2011

[eluser]mikkelz[/eluser]
I take it that updating the Input class in /system/core is a better option than creating a custom input class to override that bit of code?

Or what is the recommended method for resolving these bugs until a new version is released?

Edit:

I kind of answered my own question by going ahead and modifying the Input class with the latest change on bitbucket.

Line #542:

Code:
$str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);

It feels "cleaner" than hacking in a custom class for something small like this.

Edit 2:

Thanks for the link JuanitoDelCielo