0

I'm trying to use Summernote as an enhanced textarea field in a form. When the form is submitted, I'm sending the $_POST variable to my PHP backend. After some unexpected behavior I tried printing $_POST and noticed that Summernote adds 2 field into it - the usual form field ("description" in this case) and "files". I haven't found this behavior documented anywhere and I'm not using any file uploads inside or outside Summernote so I believe it's either a weird bug or I made a mistake somewhere. I could easily work around this issue but I'm just wondering if I'm doing something wrong and/or if there's a way to prevent it from doing this.

I'm using PHP 7.1, BS4 version of Summernote 0.8.15 and I'm not getting any console errors.

HTML/PHP:

<div class="form-group">
    <label for="summernote">Description</label>
    <textarea name="description" id="summernote" class="form-control"></textarea>
</div>

...

<?php
    if(!empty($_POST))
    {
        print_r($_POST); //Array ( other fields... [description] => test [files] => )
    }
?>

JS:

$('#summernote').summernote({
    height: 150,
    toolbar: [
        ['style', ['bold', 'italic', 'underline']],
        ['fontsize', ['fontsize']],
        ['color', ['forecolor']],
        ['para', ['ul', 'ol', 'paragraph']]
    ],
    fontSizes: ['14', '16', '18', '20', '24', '28', '32']
});
  • I haven't used Summernote before, but just by hcecking the demo on their site i can see they have an input called files and it has attribute of multiple.. I think its used to store any image files you put in the editor. – RyDog Jan 28 '20 at 00:10

1 Answers1

1

So by doing some research, it looks like Summernote by default submits images and files in base64 format. The input named 'files' is used even if you haven't chosen any images or files, this is why you are seeing the files variable in your post data.

found these whilst doing reserach:

Mention of base64: https://github.com/summernote/summernote/issues/72

Question on how to not use base64: Summernote - Image url instead of Base64

What is base64? What is base 64 encoding used for?

RyDog
  • 1,169
  • 1
  • 9
  • 12