Codeigniter:验证不会因为tinymce textarea而发生 [英] Codeigniter: Validation not happenning because of tinymce textarea

查看:107
本文介绍了Codeigniter:验证不会因为tinymce textarea而发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用tinymce作为textarea并且我使用AJAX提交我的表单。

I am using tinymce as textarea And i am submitting my form using AJAX.

由于这个tinymce插件,我的textarea没有验证。如果我从那个textarea删除这个插件,那么这个textarea正确验证。

My textarea is not validating because of this tinymce plugin. And if i remove this plugins from that textarea then this textarea is validating correctly.

为什么这个烂摊子?请帮我解决这个问题。

Why this mess? Please help me to get out from this problem.

我的浏览页面

  <script src="http://static.tinymce.com/tinymce/js/4.0b1/tinymce.min.js"></script>  
  <script type="text/javascript">
    tinymce.init({
        selector: "textarea", height: 300,
        theme_advanced_font_sizes: "10px,12px,14px,16px,24px",
        plugins: [
            "advlist autolink lists link image charmap print   anchor autolink ",
            "searchreplace visualblocks  visualchars code fullscreen",
            "insertdatetime media table contextmenu paste hr emoticons directionality"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image "
    }); 


    <!--------FORM SUBMIT AJAX ACTION -->
        $(document).ready(function() { 

            var _status = $('#status');
           $("#sendedits-form").submit(function(e)
    {
                    var postData = $(this).serializeArray();

               var formURL = $(this).attr("action");
                $.ajax({
                    url : formURL,
                    type: "POST",
                    data : postData,
                    async: true, 
                     dataType: "json",
                    success: function(dat) { 
                        if (dat.status === 'msgsent') {  // $('#status').empty();
                            alert("succes");
                        }
                        else if (dat.status === 'fail') {

                        }
                        else
                        {
                            $("#status").empty(); $('#subeditbtn').text('Submit');
                            $('#loadingimg').hide();
                            $('#subeditbtn').attr('disabled', false);
                            _status.html('<span class="err">' + dat.message + '</span>');
                            $("#status").fadeIn("slow");

                            $("#status").click(function() {
                                $("#status").fadeOut("slow");
                                return false;
                            });
                        }
                    },
                    error: function(err) {
                       // alert("Ooops! Try again later or else sends us  message regarding this issue. Thankyou!");
                    }
                });
                e.preventDefault();
            }); 


            $('.ckdeditor').keyup(function(){
          var keyed = $(this).val();
          $(".ckdeditor").html(keyed);
     });
             });
   </script>
 <!--- now my html form page --> 
 <?php $secattr = array('name' => 'sendeditsform', 'id' => 'sendedits-form'); ?>
                <?php echo form_open('article/sendedits', $secattr); ?>
                <table class="formtable" width="100%"  style="margin-top: 0%;">

                    <tr>
                        <td width="10%">&nbsp;</td>
                        <td width="90%" >&nbsp;</td>
                    </tr>

                    <tr>
                        <td width="10%" style="vertical-align: middle;text-align: right;font-weight: bolder;"><?php echo '<div id="level_removeMe">Body  &nbsp; </div>'; ?> </td>
                        <td width="90%"  align="left" valign="top"><?php echo form_textarea($fcontent);  //some text data in <ul><li></li> format generated from this same textarea ?></td>
                    </tr>

                    <tr>
                        <td width="10%" align="center" valign="bottom">&nbsp;</td>
                        <td width="90%" align="left"><input type="submit"  value="Submit"/></td>
                    </tr>    
                </table>  
                <?php echo form_close(); ?> 

控制器

 public function  sendedits()
{    $this->load->library('form_validation');
      $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('content', 'Body', 'trim|required');

        if (!$this->form_validation->run()) 
        {   //False  
            $this->_status['status'] = "error";
            $this->_status['message'] = $this->load->view('commonfiles/ajax_error_display_1', '', TRUE);
        } 

         else if ($this->form_validation->run() && $this->input->post('myId')=='')//myId=just for checking robot or human
          {     $this->_status['message'] = 'Thankyou for your edits. We will review it before publishing.'; 
            $this->_status['status'] = "msgsent";
             //send email
          } 
       echo json_encode($this->_status);    
} 


推荐答案

首先:添加ID属性你的textarea。我说'编辑选择器'是错误的。它必须是编辑器 ID :)。在序列化表单之前,添加以下代码:

Firstly: add ID attribute to your textarea. I was wrong saying 'editor selector'. It has to be editor ID :). Before serializing form, add this code:

 $('#textarea_id').html( tinymce.get('textarea_id').getContent() );

TinyMCE添加了一些HTML标签。所以解决方法是将 strip_tags([你的变量])与空白进行比较,但当然它会使codeigniter验证失效

TinyMCE adds some HTML tags. So the solution is to compare strip_tags([your variable]) to empty, but of course it will make codeigniter verification useless

这篇关于Codeigniter:验证不会因为tinymce textarea而发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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