shragi
asked on
nl2br is not working in php laravel
Hi - I have the below code for text box in the webpage.
Now when ever i enter the data with line breaks and click save, the format is missing when i come back.
Example:
In the text box i entered below information in the below format
My original code is below
I changed the code as below
so how to fix this ?
The database field is set to longtext.
Thanks
Now when ever i enter the data with line breaks and click save, the format is missing when i come back.
Example:
In the text box i entered below information in the below format
Action1 is good, but action1 is not great.Now once I clicked save and come back tomorrow or after some time to see the comments I wrote in the text area they appear like below
So please use the below actions2
1) action2
2) action3
3) action4
Action1 is good, but action1 is not great.So please use the below actions21) action22) action33) action4
My original code is below
{!! Form::textarea('action_item_comment'.(isset($action->id) ? '['.$action->id.']' : null).'', isset($action->action_item_comment) ? $action->action_item_comment : null, array('class' => 'form-control')) !!}
I changed the code as below
{!! Form::textarea('action_item_comment'.(isset($action->id) ? '['.$action->id.']' : null).'', isset($action->action_item_comment) ? nl2br(e($action->action_item_comment)) : null, array('class' => 'form-control')) !!}
Action1 is good, but action1 is not great.<br/><br/>So please use the below actions2<br>1) action2<br>2) action3<br>3) action4When I changed the code i got the output as below.
so how to fix this ?
The database field is set to longtext.
Thanks
ASKER
Hi ray - thanks for the response, yes i am using laravel blades.
regarding view source this text area is in pop up box and when i click on view source it doesn't have code related to text area.
so i inspected the element which doesn't help much.
Dinesh
regarding view source this text area is in pop up box and when i click on view source it doesn't have code related to text area.
so i inspected the element which doesn't help much.
Dinesh
OK, I get that. Did you try it like this, according to Displaying Raw Text with Curly Braces?
{!! $data->textarea !!}
ASKER
Hi ray - if you check the code the whole form is in that format - inside {!!.......!!}
This is (probably) a string variable. It's the textarea property in the $data object.
$data->textarea
In contrast, this is a bunch of nested PHP code, culminating with a function call to the textarea() static method in the Form class.
{!! Form::textarea('action_item_comment'.(isset($action->id) ? '['.$action->id.']' : null).'', isset($action->action_item_comment) ? $action->action_item_comment : null, array('class' => 'form-control')) !!}
My recommendation would be to try simplifying that expression, so you pass a string to Blade.
ASKER
Hi Ray - I am not sure how to simplify this...can you share me an example with form.
Thanks,
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Example:
Open in new window
Ref: https://laravel.com/docs/5.0/templates