简体   繁体   中英

Laravel - get the textarea value from view within TinyMCE

My problem:

Everything is appearing within the view as expected, but once the user has edited the text field, I want to then re-upload it to the database. However, within the Controller, I cannot get the text within the 'textarea'.

Current HTML set up within my view is:

{!! Form::open(array('route' => 
    array('updateReport', $report->first()->id), 'role'=>'form','id'=>'updateReport')) !!}

<textarea class="form-control" id="report" name="report" rows="15">
    {{ $report->first()->html }}</textarea>

<button type="submit" class="btn btn-labeled btn-success" aria-hidden="true">
    <span class="btn-label">
        <i class="glyphicon glyphicon-save"></i></span> Update Report</button>

{!! Form::close() !!}

Javascript section to initialise the TinyMCE:

<script type="text/javascript">
  tinymce.init({
    selector: '#report',
  menubar: false,
  browser_spellcheck: true,
  });
</script>

I have tried:

Input::all() and Input::get('report') - both return null .

How can I get the raw HTML that's newly edited and stored "behind the scenes", surely there must be a simple way?

Many thanks in advance.

如果只需要担心一个字段, tinymce.activeEditor.getContent()应该可以解决问题

You can use the setup call back to bind a change event to the editor which will trigger a save. This places the modified content back in the original textarea allowing you to post it to your script.

<script type="text/javascript">
  tinymce.init({
    selector: '#report',
    setup: function (editor) {
        editor.on('change', function () {
            tinymce.triggerSave();
        });
    },
    menubar: false,
    browser_spellcheck: true
  });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM