【问题标题】:Codeigniter 中的错误消息后的空格
【发布时间】:2022-01-23 03:34:47
【问题描述】:

我使用此代码输出错误消息:

<script>
   const successNotification = window.createNotification({
    theme: 'error',
    showDuration: 5000,
    closeOnClick: true
   });    
   successNotification({title: 'ERROR',message:'Category name is required
'});            
</script>

Category name 后面是空格,我想这样:

<script>
       const successNotification = window.createNotification({
        theme: 'error',
        showDuration: 5000,
        closeOnClick: true
       });    
       successNotification({title: 'ERROR',message:'Category name is required'});               
    </script>

这是我的 php 代码:

    $this->form_validation->set_rules('name', $this->lang->line('category'), 'trim|required|xss_clean',
        array('required' => $this->lang->line('category_required')));

    $this->form_validation->set_error_delimiters('',''); 

            if ($this->form_validation->run() === false) {
                $this->session->set_flashdata('submit-error', validation_errors());
                    redirect($this->agent->referrer());
              }

在我看来,我有这个:

<script>
   const successNotification = window.createNotification({
    theme: 'error',
    showDuration: 5000,
    closeOnClick: true
   });    
   successNotification({title: 'ERROR',message:'<?php echo $this->session->flashdata('submit-error'); ?>'});            
</script>

如何在输出中出现错误消息后删除空格?

谢谢!

【问题讨论】:

    标签: javascript php jquery codeigniter


    【解决方案1】:

    经过一番研究,我解决了。我会放在这里可能会有所帮助

    $this->session->set_flashdata('submit-error', trim(preg_replace('/\s\s+/', '', validation_errors())));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 2013-05-11
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多