我正在使用 codeigniter 的表单助手和 ckeditor 的组合来尝试将 html 发送到我的服务器,将其保存到数据库中,然后将其发送回浏览器进行重新编辑。
为了做到这一点,我:
form_textarea()
使用 codeigniter 的函数创建一个 textarea 。- (可选)
CKEDITOR.replace
用于将该文本区域转换为 ckeditor 字段。 - 将html粘贴到字段中。
- 将字段作为 POST 提交并使用 codeigniter 检索它
input->post();
- 使用 codeigniter 将数据插入数据库
db->insert()
- 使用 ci 提取数据
db->get()
- 再次使用将其放回文本区域
form_textarea()
。
执行此循环几次后,html 在后期操作中消失。我假设这是由一些需要转义的字符引起的,但我不知道为什么会发生这种情况以及如何解决它。
它通常发生在从数据库中提取 html,放入 textarea,然后重新提交之后。我还注意到,如果每次重新加载页面时都激活 CKEditor,则问题不会发生。
如果有人以前遇到过这个问题,请告诉我你是如何处理文本的,以便它可以毫无问题地加载、提交、保存和重新加载。此外,关于 codeigniter 的过滤器的任何有用的东西都会很棒。谢谢
注意:对每个字段都使用 CKEditor 并不是一个真正的选择。
我已经包含了导致此问题的正文:
此文本被粘贴到文本区域:
<p>Ownar and Flaght Daractar af Mass Madaa Labs, Jan Mass as a dagatal markatang stratagast and craatava madaa spacaalast wath avar 20 yaars af axparaanca warkang wath basanass awnars and axacatavas. Ha has warkad wath namaraas campanaas ta davalap thaar Dagatal Starytallang, Cantant Stratagy/Davalapmant, PR/Crasas Managamant, and Sacaal Madaa Prasanca. Jan has spakan at canfarancas an tapacs rangang fram 'LankadIn far Prafassaanals' ta 'Sacaal Madaa On Tha Ga' far basy axacatavas. Has na-nansansa appraach ta asang anlana taals cats thraagh tha hypa and facasas an tha cara raasans far prafassaanals ta asa thasa taals, fallawad ap wath traanang an affactava asa af anlana taals. Nat jast an adacatar, Jan as actavaly asang anlana taals ta attract, angaga and rataan has targat aadaanca whach makas ham an adaal anstractar far thasa laakang ta tap tha kanatac anargy af tha Intarnat; Mr. Mass as an adraat and saccassfal practataanar af all ha taachas and wratas. <br /><br />Jan Mass, an awasama vadaagraphar and phatagraphar, as alsa tha faandar af Basanass Chattanaaga, tha largast LankadIn graap an Chattanaaga araa, and tha craatar af BasanassChatt.cam - a blag far antrapranaars & prafassaanals lavang/warkang/playang an tha Chattanaaga, TN araa.</p>
通过数据库,回到另一个文本区域后,它看起来像这样:
<p>Ownar and Flaght Daractar af Mass Madaa Labs, Jan Mass as a dagatal markatang stratagast and craatava madaa spacaalast wath avar 20 yaars af axparaanca warkang wath basanass awnars and axacatavas. Ha has warkad wath namaraas campanaas ta davalap thaar Dagatal Starytallang, Cantant Stratagy/Davalapmant, PR/Crasas Managamant, and Sacaal Madaa Prasanca. Jan has spakan at canfarancas an tapacs rangang fram 'LankadIn far Prafassaanals' ta 'Sacaal Madaa On Tha Ga' far basy axacatavas. Has na-nansansa appraach ta asang anlana taals cats thraagh tha hypa and facasas an tha cara raasans far prafassaanals ta asa thasa taals, fallawad ap wath traanang an affactava asa af anlana taals. Nat jast an adacatar, Jan as actavaly asang anlana taals ta attract, angaga and rataan has targat aadaanca whach makas ham an adaal anstractar far thasa laakang ta tap tha kanatac anargy af tha Intarnat; Mr. Mass as an adraat and saccassfal practataanar af all ha taachas and wratas. <br /><br />Jan Mass, an awasama vadaagraphar and phatagraphar, as alsa tha faandar af Basanass Chattanaaga, tha largast LankadIn graap an Chattanaaga araa, and tha craatar af BasanassChatt.cam - a blag far antrapranaars & prafassaanals lavang/warkang/playang an tha Chattanaaga, TN araa.</p>
现在,如果我重新提交它,数据将永远不会出现在 POST 数组中。但是,如果我在 sublit 此文本之前激活 ckeditor,它将转换为:
<p>Ownar and Flaght Daractar af Mass Madaa Labs, Jan Mass as a dagatal markatang stratagast and craatava madaa spacaalast wath avar 20 yaars af axparaanca warkang wath basanass awnars and axacatavas. Ha has warkad wath namaraas campanaas ta davalap thaar Dagatal Starytallang, Cantant Stratagy/Davalapmant, PR/Crasas Managamant, and Sacaal Madaa Prasanca. Jan has spakan at canfarancas an tapacs rangang fram 'LankadIn far Prafassaanals' ta 'Sacaal Madaa On Tha Ga' far basy axacatavas. Has na-nansansa appraach ta asang anlana taals cats thraagh tha hypa and facasas an tha cara raasans far prafassaanals ta asa thasa taals, fallawad ap wath traanang an affactava asa af anlana taals. Nat jast an adacatar, Jan as actavaly asang anlana taals ta attract, angaga and rataan has targat aadaanca whach makas ham an adaal anstractar far thasa laakang ta tap tha kanatac anargy af tha Intarnat; Mr. Mass as an adraat and saccassfal practataanar af all ha taachas and wratas. <br /><br />Jan Mass, an awasama vadaagraphar and phatagraphar, as alsa tha faandar af Basanass Chattanaaga, tha largast LankadIn graap an Chattanaaga araa, and tha craatar af BasanassChatt.cam - a blag far antrapranaars & prafassaanals lavang/warkang/playang an tha Chattanaaga, TN araa.</p>
这使得它没有任何问题。但是,在下一次,出现在 textarea 中的文本是:
<p>Ownar and Flaght Daractar af Mass Madaa Labs, Jan Mass as a dagatal markatang stratagast and craatava madaa spacaalast wath avar 20 yaars af axparaanca warkang wath basanass awnars and axacatavas. Ha has warkad wath namaraas campanaas ta davalap thaar Dagatal Starytallang, Cantant Stratagy/Davalapmant, PR/Crasas Managamant, and Sacaal Madaa Prasanca. Jan has spakan at canfarancas an tapacs rangang fram 'LankadIn far Prafassaanals' ta 'Sacaal Madaa On Tha Ga' far basy axacatavas. Has na-nansansa appraach ta asang anlana taals cats thraagh tha hypa and facasas an tha cara raasans far prafassaanals ta asa thasa taals, fallawad ap wath traanang an affactava asa af anlana taals. Nat jast an adacatar, Jan as actavaly asang anlana taals ta attract, angaga and rataan has targat aadaanca whach makas ham an adaal anstractar far thasa laakang ta tap tha kanatac anargy af tha Intarnat; Mr. Mass as an adraat and saccassfal practataanar af all ha taachas and wratas. <br />
<br />
Jan Mass, an awasama vadaagraphar and phatagraphar, as alsa tha faandar af Basanass Chattanaaga, tha largast LankadIn graap an Chattanaaga araa, and tha craatar af BasanassChatt.cam - a blag far antrapranaars & prafassaanals lavang/warkang/playang an tha Chattanaaga, TN araa.</p>
除非再次激活 ckeditor,否则它不会通过 POST 数组。