Francisunoxx Francisunoxx - 4 months ago 39
PHP Question

Why dd($request) can't get the request of TinyMCE using Laravel 5.2

I don't know which the cause but I have a

tinymce
plugin with a selector which is my
textarea
. I'm trying to check if I get the request on my
textarea
which is the text editor. When I check it doesn't have any column for my
textarea
which has a id of
content
under
+request: ParameterBag


Screenshot below.

SC

As you can see here it doesn't have any key which is
content
id of my textarea. Can anyone tell me how can I solve this.

Script:

<script>
tinymce.init
({
selector: '#content',
plugins: [
'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality emoticons template paste textcolor save'
], //The plugins configuration option allows you to enable functionality within the editor.
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons | save',
save_enablewhendirty: true,
height: 400,
});

function get_editor_content()
{

// Get the HTML contents of the currently active editor
console.debug(tinymce.activeEditor.getContent());

// Get content of a specific editor:
var selectContent = tinymce.get('content').getContent();

}

</script>


I can get here the value of my textarea but still don't have any idea how can I save or insert this on my database. Any help would greatly appreciated.

Form:

<form class = "form-vertical" role = "form" method = "post" action = "{{ route('document.create')}}">

<div class = "form-group">
<label for = "title" class = "control-label">Title:</label>
<input type = "text" name = "title" class = "form-control">
</div>

<div class = "form-group">

<label for = "to" class = "control-label">To:</label>
<select onChange = "showUserOptions(this)" name = "to[]" multiple class = "form-control" id = "myUserList">

@foreach ($result as $list)
<option value = "{{ $list->id }}">{{ $list->username }}</option>
@endforeach

</select>
</div>

<div class = "form-group">

<label for = "category" class = "control-label">Category:</label>
<select onChange = "showCategoryOptions(this)" name = "category" class = "form-control" id = "myCategory">

<option selected disabled>Please select role</option>
@foreach ($resultCategory as $categoryList)
<option value = "{{ $categoryList->id }}">{{ $categoryList->category_type }}</option>
@endforeach

</select>

</div>

<div class = "form-group">
<textarea id="content"></textarea>
</div>


<div class = "form-group">
<button type = "submit" class = "btn btn-primary" onclick="get_editor_content()">Send</button>
</div>

<input type = "hidden" name = "_token" value = "{{ Session::token() }}">

</form>


Controller:

class DocumentController extends Controller
{
public function getDocuments()
{
$result = DB::table('users')->where('id', '!=', Auth::id())->get();

$resultCategory = DB::table('categories')->get();

return view ('document.create')->with('result', $result)->with('resultCategory', $resultCategory);
}

public function postDocuments(Request $request)
{
dd($request);
$this->validate($request,
[
'to' => 'required',
'title' => 'required|alpha_dash|max:255',
'category' => 'required',
'content' => 'required',
]);
}

}

Answer

Try to add a name to the textarea:

<div class = "form-group">
    <textarea id="content" name="content"></textarea>
</div>