我不确定将成功消息实施到不同的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;
}
?>
答案 0 :(得分:1)
尝试
<?php
$errorMsg = validation_errors('<div class="alert alert-error">', '</div>');
if ($errorMsg){
echo $errorMsg;
}
else{
echo 'Success message';
}
?>
答案 1 :(得分: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');
}