0
We’re using summernote in a project with Bootstrap. It’s like this:
HTML is that way:
<textarea class="md-form-control md-static" id="summernote" name="Mensagem" rows="18" ></textarea>
The Jquery:
$(document).ready(function() {
$('#summernote').summernote({
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['superscript', 'subscript']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
],
height: 350, // set editor height
minHeight: null, // set minimum height of editor
maxHeight: null, // set maximum height of editor
placeholder: 'Digite sua mensagem aqui...',
focus: true // set focus to editable area after initializing summernote
});
$('.inline-editor').summernote({
airMode: true
});
The validation of the fields is in PHP, but we are not able to validate the textarea field. We have tried:
if(empty($mensagem)){
// Mensagem de erro
}
When we gave the print_r()
in $_POST
, appears that way:
Array ( [TipoEnvio] => [Titulo] => [Mensagem] =>
) 1
I’ve used the strip_tags($mensagem,'<br><p>');
, but did not help. According to documentation of summernote:
The Editing area needs
<p><br></p>
for Focus, Even if the editor content is Empty. So Summernote Supports this method for helping to check if editor content is Empty.
And suggest using:
if ($('#summernote').summernote('isEmpty')) {
alert('editor content is empty');
}
Only we need to validate in PHP. When I give strlen($mensagem)
, it returns as it already has 11 characters, even without typing anything. How can I solve this?
Ever tried to use
empty(trim($mensagem))
?– bio
Hi bio. I’ve tried using that combination, but it didn’t work either. If there is no solution, I will have to use Jquery to validate, but we are preferring it to PHP.
– user24136
Hello dvd. I changed the post and included HTML with Jquery.
– user24136
You’re getting it on
$_POST['Mensagem']
?– Sam
Yes. In the traditional way
$mensagem = $_POST["Mensagem"];
.– user24136