简体   繁体   English

如何发布在Joomla编辑器-自定义组件中输入的内容

[英]How to POST the content entered in a Joomla Editor - Custom Component

Im developing a custom component for Joomla 3.0 and i'm using a editor field in one of my views. 我正在为Joomla 3.0开发自定义组件,我在其中一个视图中使用了编辑器字段。 I'm developing my views out of pure HTML and JS not out of Joomla XML Structure. 我是从纯HTML和JS开发视图,而不是从Joomla XML Structure开发视图。 I have successfully been able to load and use the editor field, but when i'm posting the form data to my controller using ajax, the editor field is not showing, or is null. 我已经能够成功加载和使用编辑器字段,但是当我使用ajax将表单数据发布到控制器时,编辑器字段未显示或为null。

How can i post the content of the editor to my controller using ajax ? 我如何使用ajax将编辑器的内容发布到我的控制器上?

Form Code - 表格代码-

    <form id="servicecategory-form" name="servicecategory-form" enctype="multipart/form-data">
...
<!-- description editor-->
<div class="control-group">
    <label class="control-label">
        <a href="#" data-toggle="tooltip" title="Description">
            Description
        </a>
    </label>
    <div class="controls">
        <?php
        $editor = JFactory::getEditor();
        echo $editor->display('description', '', '270', '300', '50', '10',false);
        ?>
        <p class="help-block"></p>
    </div>
</div>
...
</form>

Javascript Code - JavaScript代码-

function saveServiceCategory() {
    var form = jsn('#servicecategory-form');

        var formData = form.serialize();

        jsn.ajax({
            type: 'POST',
            url: 'index.php?option=com_centrilliontech_helloworld&task=custom.saveData&tmpl=component&format=raw',
            cache: false,
            data: formData,
            beforeSend: function() {
                jsn('#loading-modal').modal('show');
                console.log('beforeSend');
            }
        })
            .success(function(response) {
                var value = jQuery.parseJSON(response);

                if (value.error) {
                    alertBar('alert-error', 'Service Category', 'Error');
                } else {
                    alertBar('alert-info', 'Service Category', value.message);
                }
            })
            .complete(function() {
                jsn('#loading-modal').modal('hide');
                console.log('complete');
            })
            .error(function() {
                alertBar('alert-danger', 'Service Category', 'Oops! An error occurred. Please try again later.');
            });
}

Please assume that the ajax request and anything to do with the posting of data to the associated controller is working fine, which it is, the only issue is here is how can i access the content of the editor and post it to the controller so i can save it in the database. 请假设ajax请求以及与将数据发布到关联的控制器有关的一切工作正常,这是唯一的问题,这是我如何访问编辑器的内容并将其发布到控制器,所以我可以将其保存在数据库中。

Thanks for your help in advance. 感谢您的帮助。

Here's how I pass Joomla editor values through AJAX: 这是通过AJAX传递Joomla编辑器值的方法:

Either save the editor content in a hidden input or on your action element as a data attribute on the PHP/HTML side: 将编辑器内容保存在隐藏的输入中,或将操作内容保存为PHP / HTML端的数据属性:

<input type="hidden" id="element_id" value="<?php echo $editor->save( 'editor_id' ); ?>" />

Or as a data attribute on your button: 或作为按钮上的数据属性:

<a id="element_id" href="javascript:;" data="<?php echo $editor->save( 'editor_id' ); ?>">Submit</a>

Then on the Javascript side just call that input value or data attribute like this: 然后在Javascript端只需调用该输入值或数据属性,如下所示:

var message = WFEditor.getContent('element_id');

Remember if you're passing html to your controller and getting the values using jinput then you need to use raw or else it will strip the html markup from it. 请记住,如果要将html传递给控制器​​并使用jinput获取值,则需要使用raw,否则它将从中剥离html标记。

$message = $jinput->get('message', null, 'raw');

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

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