2
votes

I am using CLEditor in my application for rich text that the user will fill in.

When I validate the textarea element in my PHP server side script, I do all the checking e.g. if the element is empty.

There is a problem with this in that the source of the text editor sometimes remains despite the text being cleared.

Here is an example of what I mean:

Say I have a rich text editor as shown below and I have the heading 'write your first page!'.

enter image description here

Here is how the source looks for the above picture: enter image description here

Then when I remove the text only and NOT any empty lines remaining, the source around the text remains as shown below:

enter image description here

The PHP empty function is going not going to pass as it's technically not empty because of the source code contained in the text editor.

The issue with this is I cannot rely on the user to clear the whole screen including empty lines, so is there a way I can get rid of any source that doesn't contain actual content as the second image above shows?

HTML:

<textarea id="textarea" name="chapter"><h4 style="text-align: center;">Write your first page!</h4></textarea>
1
sorry but i really think this is real correct user entry. You may know if value is empty or not but you don't know if its html tags are empty. I think its not posibble without parse html entrydaremachine
you may see .. the editor doesn't know too. If he has known html tag is empty, he removed itdaremachine
Yes, user entry is fine but the problem is the html tags. If I do if(empty($_POST['chapter']){...} with the above, it will always return false because it contains html tags but no actual content within them. So is there a way around that?user3574492

1 Answers

7
votes

If I understood well your problem, you want to know if there is some text or just HTML tags.

In PHP, you can do the follow:

$text = trim(strip_tags($chapter));
if ($text == ''){
   // just HTML tags
}

The strip_tags function removes the HTML tags.

The trim function remove white spaces, break lines, etc...