Welcome Guest, Not a member yet? Register   Sign In
Textarea field/data does not recognize “New Line/Return Key"
#1

[eluser]justmelat[/eluser]
I ask a question in this thread:
http://ellislab.com/forums/viewthread/181765/

regarding the fact that my end of line returns were being ignored. I was quite proud of myself because i keep searching the forum and found a question from Mike Cocklin where he had a solution using nl2br. This worked great and I thought I was done, then I remembered that my clients have the ability to copy one request's data into a new request, so they don't have to start from scratch each time. Because of this capability, when the text field is re-populated [after clicking the "Copy data from previous request" link]it has <br> tags at the end of each line, so if the client submits the request without removing the <br> tags from the textarea fields, when the data detail is shown, an extra line is added making it appear that the user hit the enter key twice(double space). See Images

Here is the code on which I added the nl2br:
case FIELD_TEXT_AREA:
$fieldHtml = nl2br(inputOrText($mode, "textarea", $field->getValue(), array("id"=>$field->getId(), "class"=>"valuetext", "name"=>$field->getId(), "rows"=>"3","cols"=>"60", $jsFunctionCalls), array("class"=>"valuetext")));
break;

so I am thinking I should have done something else. Can anyone help?

[Linux and CI 1.7.1.]
#2

[eluser]Pascal Kriete[/eluser]
Don't use nl2br when you put the data into form elements, only call it when displaying the text in html.

Alternatively, you could reverse the effects of nl2br:
Code:
function br2nl($str) {
    return str_replace("<br />", "\n", $str);
}




Theme © iAndrew 2016 - Forum software by © MyBB