Search code examples
laravelsummernote

Summernote not working with laravel form


{!! Form::open(array('route' => 'posts.store', 'files' => true)) !!}
{{ Form::label('title', 'Title:') }}
{{ Form::text('title', null, array('class' => 'form-control'))}}

{{ Form::label('slug', 'Slug:') }}
{{ Form::text('slug', null, array('class' =>'form-control', 'required' =>
'', 'minlength' => '5', 'maxlength' => '255')) }}

{{ Form::label('category_id', 'Category:') }}
    <select class="form-control" name="category_id">
     @foreach($categories as $category)
       <option value='{{ $category->id }}'>{{ $category->name }}      
       </option>
     @endforeach
    </select>

{{ Form::label('tags', 'Tags:') }}
    <select class="form-control select2-multi" name="tags[]" multiple="multiple">
     @foreach($tags as $tag)
       <option value='{{ $tag->id }}'>{{ $tag->name }} </option>
     @endforeach
     </select>


{{ Form::label('body', 'Blog post:') }}                  
{{ Form::textarea('body', null, array('class' => 'form-control', 'id'=>'summernote', 'name'=>'editordata'))}}

{{ Form::submit('Create Post', array('class' => 'btn btn-success btn-lg btn-block', 'style' => 'margin-top: 20px'))}}
{!! Form::close() !!}

I have a problem, when I write something to the textarea or add a picture with summernote, and click Create Post I get an a error 'The body field is required'. I think my problem is with this line:

{{ Form::label('body', 'Blog post:') }}                  
{{ Form::textarea('body', null, array('class' => 'form-control', 'id'=>'summernote', 'name'=>'editordata'))}}

Does anyone have a solution for this?


Solution

  • I think the problem is with your array

    {{ Form::textarea('body', null, array('class' => 'form-control', 'id'=>'summernote', 'name'=>'editordata'))}}
    

    You explicitly overwrite the name attribute of your html textarea. Either remove the name => .. or use the following:

    {{ Form::textarea('body', null, array('class' => 'form-control', 'id'=>'summernote', 'name'=>'body'))}}