如何使用id将其加载到视图中?
这是我的观点
<div id="register" class="animate form">
<section class="login_content">
<form <?php echo form_open('User/register'); ?>
<h1>Create Account</h1>
<div class="inputlogin">
<div class="form-group">
我将如何将其传递给
if ($this->form_validation->run() === false) {
// validation not ok, send validation errors to the view
$index['title']="Welcome to Hoovie";
$index['mainContent']="login";
$index['results'] = $this->users_model->get_category();
$this->load->view('includes/redirect', $index, $data);
答案 0 :(得分:0)
首先,form_open标记会生成<form>
,因此您无法在表单内部回显它<form <form>>
这里是视图中登录表单的示例:
echo form_open('path/to/controller');
echo form_input(array(
'name' => 'username',
'class' => 'form-control input-lg',
'placeholder' => 'username'
));
echo form_password(array(
'name' => 'password',
'class' => 'form-control input-lg',
'placeholder' => 'password'
));
echo form_submit(array(
'name' => 'LoginSubmit',
'class' => 'btn btn-lg btn-info',
'value' => 'Login'
));
echo form_close();}
在控制器内部之后,如果没有自动加载,则必须激活form_validation库,然后必须为输入设置规则
示例:
$dugme = $this->input->post('LoginSubmit');
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if(isset($dugme) && $this->form_validation->run()){
//if everything ok, do something
}
else {
//if validation did not pass load view
$this->load_view('login'); }
然后在视图内部你必须回显错误
//I am using bootstrap so alert-danger will show this div with red background
<?php echo validation_errors('<div class="alert alert-danger">','</div>');?>
您可以在此处查看有关表单验证的更多信息:
Codeigniter 3:https://www.codeigniter.com/userguide3/libraries/form_validation.html Codeigniter 2:https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html