使用Dojo Rich Text Editor提交表单 [英] Submitting a form with a Dojo Rich Text Editor

查看:149
本文介绍了使用Dojo Rich Text Editor提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何提交包含Dojo Rich Text Editor的表单?



我已经尝试将name属性添加到使用dojoType =dijit.Editor进行装饰的元素中,但是我看不到任何我的接收过程中的HTML。



我已经检查了文档,我没有看到任何明确的示例(除了将有问题的表单的提交事件与设置数据的另一个功能相连一个隐藏的输入与富文本编辑器的值)。



我会假设有一些更容易的方法来做到这一点? p>

解决方案

这里我可以将值发送到服务器,并能够以提交的值重新显示为编辑器的内部显示值。

 < html> 
< head>
< style type =text / css >
@importhttp://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css;
< / style>
< script src =djlib / dojo / dojo.jstype =text / javascriptdjConfig =parseOnLoad:true>< / script>
< link rel =stylesheethref = djlib / dojox / grid / resources / Grid.csstype =text / css/>
< body class =claro>
<?php if(count($ _ POST)> 0){
echo'< script> function dumpSubmittedEditorValue(){}< / script>';
echo< script> var submittedEditorValue ='$ _POST [ed1]'< / script>;
}
?>
< form jsId =frm1dojoType =dijit.form.Formmethod =postaction =<?php echo $ _SERVER ['PHP_SELF'];?>>
< input type =hiddenname =ed1/>
< span dojoType =dijit.form.Button>
提交
< script type =dojo / methodevent =onClick>
frm1.submit();
< / script>
< / span>
< / form>
< div dojoType =dijit.Editorid =editor1>
< script type =dojo / method>
this.hiddenField = dojo.query([name = ed1])[0];
//console.log(this.hiddenField);
/*dojo.connect(this.document.body,'onload',function(){
console.log(A);
console.log(this.document.body );
})* /
< / script>
< script type =dojo / methodevent =onChangeargs =val>
//第一格式。 < p为H.嗨 - 应该是 - < p> HI
var str = dojo.string.trim(val);

var tagsEncoded = dojox.html.entities.encode(str,encodecustomMap);
var whiteSpaceEncoded = tagsEncoded.replace(/ \s / ig,%20);
this.hiddenField.value = whiteSpaceEncoded;
console.log(this.hiddenField.value)
//console.log(dojox.html.entities.decode(whiteSpaceEncoded.replace(/%20/ig,),decodecustomMap))


< / script>


< / div>
< script>
var decodecustomMap = [
[\\\<,lt],
[\\\>,gt],
[\\\& ,amp]
];
var encodecustomMap = [
[\\\<,lt],
[\\\>,gt]
];
< / script>
< / body>

< script>
dojo.require(dijit.Editor);
dojo.require(dojox.html.entities);
dojo.require(dijit.form.Form);

dojo.addOnLoad(function(){
console.log(dojo.query(iframe,dijit.byId(editor1)。domNode))
dojo。 connect(dojo.query(iframe,dijit.byId(editor1)。domNode)[0],'onload',function(){
console.log(this.contentDocument.body)
this.contentDocument.body.innerHTML = getEditorIntialValue();
})
函数getEditorIntialValue(){
if(typeof submittedEditorValue!=undefined){
submittedEditorValue = dojox .html.entities.decode(submittedEditorValue,decodecustomMap);
submittedEditorValue = submittedEditorValue.replace(/%20 / ig,& nbsp;);
return submittedEditorValue;
// dijit .byId(editor1)。document.body.innerHTML = submittedEditorValue;
}
else {
return;
}
}

})
< / script>
< / html>


Does anyone out there know how to submit a form that contains a Dojo Rich Text Editor?

I've tried adding the "name" attribute to my element that is decorated with dojoType="dijit.Editor", however, I don't see any of the HTML on my receiving process.

I've checked the documentation and I don't see any clear example (other than connecting the on submit event of the form in question with another function that sets the data of a hidden input with the "value" of the Rich Text Editor").

I would assume there has to be some "easier" way to do this?

解决方案

Here im able to send the value to the server, and able to redisplay in the submitted value as intial display value for the Editor.

<html>
<head>
<style type="text/css">
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css";   
</style>        
<script src="djlib/dojo/dojo.js" type="text/javascript" djConfig="parseOnLoad:true"></script>   
 <link rel="stylesheet" href="djlib/dojox/grid/resources/Grid.css" type="text/css" />
<body class="claro">
    <?php if(count($_POST) > 0) {
            echo '<script>function dumpSubmittedEditorValue(){}</script>';
            echo "<script>var submittedEditorValue = '$_POST[ed1]'</script> ";
        } 
    ?>
    <form jsId="frm1" dojoType="dijit.form.Form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="hidden" name="ed1" />
        <span dojoType="dijit.form.Button">
            Submit
            <script type="dojo/method" event="onClick">
                frm1.submit();
            </script>
        </span>
    </form>
    <div  dojoType="dijit.Editor" id="editor1">         
        <script type="dojo/method">
            this.hiddenField = dojo.query("[name=ed1]")[0];
            //console.log(this.hiddenField);
            /*dojo.connect(this.document.body,'onload',function(){                  
                console.log("A");
                console.log(this.document.body);
            })*/
        </script>
        <script type="dojo/method" event="onChange" args="val">
            //1st format. <p>     hi - should be - <p>HI
            var str = dojo.string.trim(val);

            var tagsEncoded = dojox.html.entities.encode(str, encodecustomMap);
            var whiteSpaceEncoded= tagsEncoded.replace(/\s/ig,"%20");
            this.hiddenField.value = whiteSpaceEncoded;
            console.log(this.hiddenField.value)
            //console.log(dojox.html.entities.decode(whiteSpaceEncoded.replace(/%20/ig," "), decodecustomMap))


        </script>


    </div>
    <script>
        var decodecustomMap = [                 
                ["\u003C", "lt"],
                ["\u003E", "gt"],
                ["\u0026", "amp"]
            ];
            var encodecustomMap =  [
                ["\u003C", "lt"],
                ["\u003E", "gt"]
            ];
    </script>
</body>

<script>      
    dojo.require("dijit.Editor");
    dojo.require("dojox.html.entities");
    dojo.require("dijit.form.Form");

    dojo.addOnLoad(function(){
        console.log(dojo.query("iframe", dijit.byId("editor1").domNode))
        dojo.connect(dojo.query("iframe", dijit.byId("editor1").domNode)[0],'onload',function(){
            console.log(this.contentDocument.body)
            this.contentDocument.body.innerHTML = getEditorIntialValue();
        })
        function getEditorIntialValue(){
            if(typeof submittedEditorValue != "undefined"){
                submittedEditorValue = dojox.html.entities.decode(submittedEditorValue,decodecustomMap);
                submittedEditorValue  = submittedEditorValue.replace(/%20/ig,"&nbsp;");
                return submittedEditorValue;
                //dijit.byId("editor1").document.body.innerHTML = submittedEditorValue;
            }
            else{
                return "";
            }
        }

    })
</script>
</html>

这篇关于使用Dojo Rich Text Editor提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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