0

我不确定将成功消息实现到不同 div 的最佳方法是什么。

当页面加载时,我也将错误 div 加载到我的视图中,为什么?我希望它仅在出现错误时才显示。

如果没有错误,我如何更改 div 并包含成功消息?

看法:

<div class="alert alert-error">
    <?php echo validation_errors();?>
</div>

控制器:

if($this->form_validation->run() === TRUE)
            {
                $userData = array(
                    'fName' => $this->input->post('userFirstName', TRUE),
                    'lName' => $this->input->post('userLastName', TRUE),
                    'email' => $this->input->post('userEmail', TRUE),
                    'password' => sha1($this->input->post('userPassword', TRUE))
                );  

                $this->db->escape($userData);
                $this->user_model->addUser($userData);
            }

            $data['contentMangement'] = $this->options_model->systemOptions();
            $data['pageTitle'] = 'Add User';
            $this->load->view('_assets/header', $data);
            $this->load->view('addUser', $data);
            $this->load->view('_assets/footer');
    }

更新:

<?php 

    $errorMessage = validation_errors('<div class="alert alert-error">', '</div>'); 
    $successMessage = '<div class="alert alert-success"><strong>Thank You</strong> Your User Has Been Added';   
        if($errorMessage)
        {
            echo $errorMessage;
        }else{
            echo $successMessage;
        }

    ?>
4

2 回答 2

1

尝试

<?php 
$errorMsg = validation_errors('<div class="alert alert-error">', '</div>');
if ($errorMsg){
    echo $errorMsg;
}
else{
    echo 'Success message';
}
?>

错误分隔符

于 2012-06-12T23:13:44.667 回答
0

我已通过以下方式解决了此问题:

    if($this->form_validation->run() === TRUE)
        {
            $userData = array(
                'fName' => $this->input->post('userFirstName', TRUE),
                'lName' => $this->input->post('userLastName', TRUE),
                'email' => $this->input->post('userEmail', TRUE),
                'password' => sha1($this->input->post('userPassword', TRUE))
            );  

            $this->db->escape($userData);
            $this->user_model->addUser($userData);

            $data['contentMangement'] = $this->options_model->systemOptions();
            $data['pageTitle'] = 'Add User';
            $data['message'] = '<div class="alert alert-success"><strong>Thank You</strong> Your User Has Been Added';
            $this->load->view('_assets/header', $data);
            $this->load->view('addUser', $data);
            $this->load->view('_assets/footer');

        }elseif($this->form_validation->run() === FALSE)
        {
            $data['contentMangement'] = $this->options_model->systemOptions();
            $data['pageTitle'] = 'Add User';
            $data['message'] = validation_errors('<div class="alert alert-error">', '</div>'); 
            $this->load->view('_assets/header', $data);
            $this->load->view('addUser', $data);
            $this->load->view('_assets/footer');
        }
于 2012-06-13T00:42:50.590 回答