Rich Text Editor的字符串长度限制 [英] String length limitation for Rich Text Editor

查看:549
本文介绍了Rich Text Editor的字符串长度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的Web应用程序中广泛使用富文本编辑器(tiny_mce).我似乎无法理解的一个问题是如何限制用户输入,以使生成的内容的长度适合我的数据库字段.我通常会用于非富文本内容的字符计数器几乎没有用,因为用户看不到(或不知道或不在乎)幕后生成的HTML.即,如果我将输入限制为100个字符,并且用户输入99个字符,则由于用于在幕后构造其内容的html标签,它们仍可能会超出字符数限制.

I'm using rich text editors (tiny_mce) pretty widely in a web application I'm developing. An issue I can't seem to get my head around is how to limit user input so that the length of generated content fits in my database field. Character counters, which I would normally use for non rich-text content, are pretty useless because the user does not see (or know or care about) the HTML being generated behind the scenes. i.e. If I limit the input to 100 characters and the user types 99 characters they will still likely exceed the character limit because of the html tags used to structure their content behind the scenes.

我看到的选项是:

  • 不采取任何行动,并希望最好.显然不是真正的选择.尝试保存到数据库(在这种情况下为mysql)时,插入很有可能会不正常地失败.
  • 验证生成的HTML的长度,如果超过允许的长度,则向用户提供一条消息.这将使据其所知已满足文本输入要求的用户感到困惑.当他实际上只输入了99个字符时,告诉他已经超过了限制,只会使他感到困惑/激怒
  • 使用 hope 将数据库字段设置为超大字段,以使其永远不会被超出.似乎是个坏主意...
  • Do nothing and hope for the best. Obviously not really an option. There is a good chance that the insert will fail ungracefully when attempting to save to the db (mysql in this case).
  • Validate the length of the generated HTML and provide user with a message if it exceeds allowed length. This will be confusing to the user who, to the best of his knowledge has met the requirements for text entry. Telling him that he has exceeded the limit when, in fact, he has only entered 99 characters, would only server to confuse/enrage
  • Make the database field super large with the hope that it will never be exceeded. Seems like a bad idea...

这必须是一个经常遇到的问题.最好的解决方案是什么?

This must be a commonly encountered issue. What is the best solution here?

推荐答案

提交表单时,请使用Javascript检查提交字段的长度.

When the form submit, do a Javascript check on the length of the field being submitted.

至于您的选择,

问::什么都不做,希望最好.

Q: Do nothing and hope for the best.

A:不起作用.有些人会尝试一些东西

A: Won't work. Some will will try something

问::验证生成的HTML的长度,如果超出允许的长度,则向用户提供一条消息.

Q: Validate the length of the generated HTML and provide user with a message if it exceeds allowed length.

A:我最近也遇到过类似情况.我在页面上显示了一条静态消息,说限制为10,000,但实际上检查了50,000.这工作了几个月,直到有人从MS Word复制并粘贴出来.用户看到了5,000个字符,但编码的方式超过了100,000个

A: I recently had a similar situation. I put a static message on the page that said the limit was 10,000, but I actually checked for 50,000. This worked for several months until someone copied and pasted out of MS Word. The user saw 5,000 characters, but it was encoded in way over 100,000

问:使数据库字段超大,希望它不会被超出.似乎是个坏主意...

Q: Make the database field super large with the hope that it will never be exceeded. Seems like a bad idea...

A:根据您的数据库和版本,这是可以容忍的,不是理想的,而是可以容忍的.

A: Depending on your database and vesion, this could tolerable, not ideal, but tolerable.

这篇关于Rich Text Editor的字符串长度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆