我输出错误消息,代码为:
<script>
const successNotification = window.createNotification({
theme: 'error',
showDuration: 5000,
closeOnClick: true
});
successNotification({title: 'ERROR',message:'Category name is required
'});
</script>
类别名称是必需的之后,它是一个空格,我想是这样的:
<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>
如何删除输出中错误消息后的空格?
谢谢!
经过一番研究,我解决了这个问题。我会放在这里可能会帮助
$this->session->set_flashdata('submit-error', trim(preg_replace('/ss+/', '', validation_errors())));