0

データベースへの保存は良いです。

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

データベースから取得すると、バックスラッシュが取り除かれます。

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

CodeIgniterを使用するプロジェクトに取り組んでいます。メールアドレスを検証するフォームがあり、OK の場合は DB に保存します。Tinymceテキストエリア エディタを使用しており、データをこのデータベースに保存すると、ページが正常に表示されます。問題は、データをテキストエリアに戻すときに、バックスラッシュがないために検証が機能しないことです。

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 に答える