简体   繁体   English

通过CK编辑器获得价值并存储数据

[英]Getting Value and Storing data through CK Editor

In a form I have a field called Description . 在表单中,我有一个称为Description的字段。 Through CKEditor I need to pass that value and store it in my database. 通过CKEditor,我需要传递该值并将其存储在数据库中。 Can anyone help me out? 谁能帮我吗? Here is my code: 这是我的代码:

<div id="descriptionMore" style="margin-bottom:20px;margin-top: 38px;margin-left: 101px;">
    <aui:layout>
        <aui:column columnWidth="240">
            <liferay-ui:input-editor width="880" cssClass="richText" />
        </aui:column>
    </aui:layout>
</div>

First of all, make sure you are using aui:form . 首先,请确保您正在使用aui:form

Link which will be useful for you. 链接将对您有用。

This will defiantly be useful for you. 这无疑将对您有用。

    <%
    Content content = (Content) request.getAttribute(ApplicationConstants.CONTENT);      
    %>
  <portlet:actionURL var="saveOrUpdateContentUrl" name="saveOrUpdateContent">
        <portlet:param name="redirect" value="<%=currentURL%>" />
    </portlet:actionURL>
    <liferay-ui:header title='<%= (content==null) ? "new-content" : "edit-content"  %>' backURL="<%=redirect %>" />

    <aui:form method="post" name="content_fm" onSubmit='<%= "event.preventDefault(); " + renderResponse.getNamespace() + "saveEntry();" %>'>
        <aui:fieldset>
            <aui:field-wrapper label="product-content">
                <liferay-ui:input-editor />
                <aui:input name="content" id="content" type="hidden" />
            </aui:field-wrapper>

            <aui:button-row>
                <aui:button type="submit" />
            </aui:button-row>

        </aui:fieldset>
    </aui:form>
    <script type="text/javascript">
        function <portlet:namespace />initEditor() {
            return '<%= UnicodeFormatter.toString((content==null)? StringPool.BLANK : content.getContent()) %>';
        }
        function <portlet:namespace />getContent() {
            return window.<portlet:namespace />editor.getHTML();
        }
        function <portlet:namespace />saveEntry() {
            document.<portlet:namespace />content_fm.action = '<%=saveOrUpdateContentUrl%>';
            document.<portlet:namespace />content_fm.<portlet:namespace />content.value = <portlet:namespace />getContent();
            alert(<portlet:namespace />getContent());
            submitForm(document.<portlet:namespace />content_fm);
        }
    </script>

This above code is properly working in Liferay 6.2. 上面的代码在Liferay 6.2中正常工作。 You should fetch CKEditor content using alloy script or javascript and set in hidden parameter for storing the value. 您应该使用Alloy脚本或javascript获取CKEditor内容,并设置隐藏参数以存储值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM