0

保存到数据库是好的。

var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;   

从数据库中检索会去掉我的反斜杠。

var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;

我正在开发一个使用CodeIgniter的项目。我有一个验证电子邮件地址的表单,如果可以,则保存到数据库。我正在使用Tinymce textarea 编辑器,我将数据保存到这个数据库,我的页面显示正常。问题是当我将数据返回到 textarea 时,由于缺少反斜杠,验证不起作用。

我不确定它是来自CodeIgniter还是Tinymce的问题。

<script type="text/javascript">
window.addEvent('domready', function(){
    var submit = $('submit');
    var cancel = $('cancel');

    if(submit)
    {
        submit.addEvent('click', function(){

            $('loading').set('html', '<img src="/v5d/system/application/views/images/loading-green.gif" alt="" /> &nbsp; Processing. Please wait...');
            $('loading').set('styles', {'display': 'block'});

            var purl = $('purl').get('value');
            var formid = $('formid').get('value');

            var elementProperty = new Array();
            var elcount = 0;
            var elname='', elvalue='';
            var eldetail;
            var elreq = '';
            var valerror = 0;
            var valerror1 = 0;

            var formelements = $('survey').getChildren('input');

                            // BACKSLASH ISSUE
                           var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;


            formelements.each(function(item, index){
                eldetail = formelements[index];
                elname = eldetail.get('name');
                if(eldetail.get('type') == 'text')
                {
                    elvalue = eldetail.get('value');
                    elreq = eldetail.get('class');
                    if(elreq == 'required' && elvalue == '')
                    {
                        valerror++;
                    } 
                    else if(elreq == 'required' && !emailReg.test(elvalue))
                    {
                        valerror1++;
                    } 
                }
                else if(eldetail.get('type') == 'radio')
                {
                    var radioLength = eldetail.length;
                    if (radioLength == undefined) {
                        if (eldetail.checked) {
                            elvalue = eldetail.value;
                        }
                    }
                    for(var i = 0; i < radioLength; i++) {
                        if(eldetail[i].checked) {
                            elvalue = eldetail[i].value;
                        }
                    }
                }
                else if(eldetail.get('type') == 'checkbox')
                {
                    elvalue = '';
                    var radioLength = eldetail.length;
                    if (radioLength == undefined) {
                        if (eldetail.checked) {
                            elvalue = eldetail.value;
                        }
                    }
                    for(var i = 0; i < radioLength; i++) {
                        if(eldetail[i].checked) {
                            elvalue += ',' + eldetail[i].value;
                        }
                    }
                }
                elementProperty[elcount] = new itemstruct(elname, elvalue);
                elcount++;
            });

            formelements = $('survey').getChildren('textarea');
            formelements.each(function(item, index){
                eldetail = formelements[index];
                elname = eldetail.get('name');
                elvalue = eldetail.value;
                elreq = eldetail.get('class');
                if(elreq == 'required' && elvalue == '')
                {
                    valerror++;
                }
                elementProperty[elcount] = new itemstruct(elname, elvalue);
                elcount++;
            });

            formelements = $('survey').getChildren('select');
            formelements.each(function(item, index){
                eldetail = formelements[index];
                elname = eldetail.get('name');
                elvalue = eldetail.get('value');
                elementProperty[elcount] = new itemstruct(elname, elvalue);
                elcount++;
            });


            var surveysubmit = new Request({
                url: '/v5d/index.php/ajax/submitSurvey',
                method: 'post',
                data:{
                    'elementproperty': elementProperty,
                    'formid': formid,
                    'purl': purl,
                    'state': 'final'
                },

                onComplete: function(responseText){
                    if (!responseText || responseText == '' || responseText == false || responseText == 'FALSE') 
                    {
                        $('loading').set('html', 'Error occured');
                    }
                    else
                    {
                        $('loading').set('html', 'Form successfully submitted');
                        //window.location.reload();
                    }
                }
            });

            if (valerror == 0) 
            {
                 if (valerror1 != 0) 
                 {
                 $('loading').set('html', 'Please right email.');
                 }
                 else 
                 {
                 surveysubmit.send();
                 }
            }

            else
            {
                $('loading').set('html', 'Please fillup all required fields.');
            }
        });
    }

    if(cancel)
    {
        cancel.addEvent('click', function(){
            var choice = confirm('Sure want to leave the survey?');
            if(choice)
            {
                var purl = $('purl').get('value');
                var formid = $('formid').get('value');

                var elementProperty = new Array();
                var elcount = 0;
                var elname='', elvalue='';
                var eldetail;
                var elreq = '';
                var valerror = 0;

                var formelements = $('survey').getChildren('input');

                formelements.each(function(item, index){
                    eldetail = formelements[index];
                    elname = eldetail.get('name');
                    if(eldetail.get('type') == 'text')
                    {
                        elvalue = eldetail.get('value');
                        elreq = eldetail.get('class'); 
                    }
                    else if(eldetail.get('type') == 'radio')
                    {
                        var radioLength = eldetail.length;
                        if (radioLength == undefined) {
                            if (eldetail.checked) {
                                elvalue = eldetail.value;
                            }
                        }
                        for(var i = 0; i < radioLength; i++) {
                            if(eldetail[i].checked) {
                                elvalue = eldetail[i].value;
                            }
                        }
                    }
                    else if(eldetail.get('type') == 'checkbox')
                    {
                        elvalue = '';
                        var radioLength = eldetail.length;
                        if (radioLength == undefined) {
                            if (eldetail.checked) {
                                elvalue = eldetail.value;
                            }
                        }
                        for(var i = 0; i < radioLength; i++) {
                            if(eldetail[i].checked) {
                                elvalue += ',' + eldetail[i].value;
                            }
                        }
                    }
                    elementProperty[elcount] = new itemstruct(elname, elvalue);
                    elcount++;
                });

                formelements = $('survey').getChildren('textarea');
                formelements.each(function(item, index){
                    eldetail = formelements[index];
                    elname = eldetail.get('name');
                    elvalue = eldetail.value;
                    elreq = eldetail.get('class');
                    elementProperty[elcount] = new itemstruct(elname, elvalue);
                    elcount++;
                });

                formelements = $('survey').getChildren('select');
                formelements.each(function(item, index){
                    eldetail = formelements[index];
                    elname = eldetail.get('name');
                    elvalue = eldetail.get('value');
                    elementProperty[elcount] = new itemstruct(elname, elvalue);
                    elcount++;
                });


                var surveysubmit = new Request({
                    url: '/v5d/index.php/ajax/submitSurvey',
                    method: 'post',
                    data:{
                        'elementproperty': elementProperty,
                        'formid': formid,
                        'purl': purl,
                        'state': 'final'
                    },

                    onComplete: function(responseText){
                        if (!responseText || responseText == '' || responseText == false || responseText == 'FALSE') 
                        {
                            $('loading').set('html', 'Error occured');
                        }
                        else
                        {
                            $('loading').set('html', 'Form successfully submitted');
                            //window.location.reload();
                        }
                    }
                });
                surveysubmit.send();

                window.location.href='/v5d/'+purl;
            }
        });
    }
});

var itemstruct = function(elname, elvalue)
{
    this.elname = elname;
    this.elvalue = elvalue;


}

4

1 回答 1

0

使用此方法,您可以将数据从数据库中检索回 tinymce 编辑器。

tinyMCE.activeEditor.setContent(data);
于 2014-12-23T10:52:53.620 回答