Perocat
Perocat

Reputation: 1521

How to check if CKEDITOR textarea is empy

I have a CKEDITOR Text area. The field will never be empty because the CKEDITOR always write

<p>&nbsp;</p>

also if the field contains no user input.

Is there a way to check if the field is empty (no user input)? Because: $_POST['textarea'] == '' returns false also if user input is null.

Upvotes: 1

Views: 2287

Answers (1)

Spiny Norman
Spiny Norman

Reputation: 8347

Well, if it consistently adds the <p>&nbsp;</p> how about this?

if (in_array($_POST['textarea'], array('<p>&nbsp;</p>', '')))

or:

if (str_replace('<p>&nbsp;</p>', '', $_POST['textarea']) == '')

This will also return true if the user inadvertently presses enter, but doesn't add any text.

EDIT:

You can take this as far as you like, depending on your notion of "empty input":

if (trim(str_replace('&nbsp', '', strip_tags($_POST['textarea']))) == '')

etc.

EDIT some more:

Turns out this has been discussed before: Validate FCKEditor blank or not

Upvotes: 1

Related Questions