1

I am getting raw html from my controller and getting it into textarea. there is different type of fields as text select or also can be textarea which will be print in textbox as raw html. its working fine for all fields except textarea.

when there is a field include with textarea type then below buttons string code not comes in text box and code of textarea type shows but without ending tag as

here is my code.

 foreach($fields as $field){
    $type = $field->type;
switch($type) {
   case 'textarea':
    $str .=    '<div class="form-group">
                    <label class="control-label col-md-3">'.$custom_field->name.'
                    </label>
                    <div class="col-md-8">
                        <div class="input-icon right">
                            <i class="fa"></i>
                            <textarea name="'.$field->id.'" class="form-control" rows="8"></textarea>
                        </div>
                    </div>
                </div>';
            break;
      }
}

Now every thing works fine except when textarea type included. problem is if there is textarea type then below buttons not appear and also not ending tag of textarea

this end of html out put is as without buttons sting and without endtag

`<div class="form-group">
                        <label class="control-label col-md-3">Description
                        </label>
                        <div class="col-md-8">
                            <div class="input-icon right">
                                <i class="fa"></i>
                                <textarea name="17" class="form-control" rows="8">`

please help where its wrong

Ramzan Mahmood
  • 1,881
  • 2
  • 21
  • 46
  • Have you check the HTML it is generating? View the source of the page and show what it's generating around that text area field. – Nigel Ren May 12 '17 at 06:27
  • 1
    Oh - and the idea of generating HTML in your controller is entirely wrong! This is the Controller, HTML should be in the View - that's why they are called that, not just for convenience. – Nigel Ren May 12 '17 at 06:28
  • yes html is generating i am getting both form and raw html . form appears fine but issue in raw html @NigelRen – Ramzan Mahmood May 12 '17 at 06:30
  • @bluemoon Try this: http://stackoverflow.com/a/1638832/4771277 – Autista_z May 12 '17 at 06:39
  • @Autista_z its a different. here in my case its work when i have only one type textarea when any other also added its give the issue – Ramzan Mahmood May 12 '17 at 06:50
  • 1
    @bluemoon Yea, but i think, that this is problem. It ends parent textarea by using in your Raw code. If you use input or select, it does not end parent textarea. But if you use encoded chars, it should not end it. Look: https://jsfiddle.net/dfjkwzye/ – Autista_z May 12 '17 at 07:05
  • @bluemoon you are welcome. I wrote it as Answer as well, just accept it, so other people with same problem can find solution too. – Autista_z May 12 '17 at 07:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144033/discussion-between-blue-moon-and-autista-z). – Ramzan Mahmood May 12 '17 at 07:21
  • why generating html inside controller? why not use the power of laravel? – claudios May 12 '17 at 07:23

1 Answers1

1

You just replace < with &lt; and > with &gt;

Everything else is OK.

Just edit your case to:

case 'textarea':
$str .=    '<div class="form-group">
                <label class="control-label col-md-3">'.$custom_field->name.'
                </label>
                <div class="col-md-8">
                    <div class="input-icon right">
                        <i class="fa"></i>
                        <textarea name="'.$field->id.'" class="form-control" rows="8">&lt;/textarea&gt;
                    </div>
                </div>
            </div>';
        break;
Autista_z
  • 2,491
  • 15
  • 25