我试图在错误的提交中保留表单值我使用了set_value但是它仍然无法正常工作。
我不知道我错在哪里
这是我的控制器:
public function createOrgUsers() {
//Validating Name Field
$this->form_validation->set_rules(
'temp_username', 'Username', 'required|min_length[5]|max_length[12]|is_unique[users.username]', array(
'required' => 'You have not provided %s.',
'is_unique' => 'This %s already exists.'
)
);
$this->form_validation->set_rules('temp_firstname', 'First Name', 'required');
$this->form_validation->set_rules('temp_lastname', 'Last Name', 'required');
$this->form_validation->set_rules('temp_password', 'Password', 'required');
$this->form_validation->set_rules('temp_confirm_password', 'Password Confirmation', 'required|matches[temp_password]');
$this->form_validation->set_rules('temp_emailid', 'Email', 'required|valid_email|is_unique[users.email]');
if ($this->form_validation->run() == FALSE) {
// $this->session->set_flashdata('error', 'User not created.');
redirect('Organisation/createNewuser');
} else {
//Setting values for tabel columns
$data = array(
'username' => $this->input->post('temp_username'),
'firstname' => $this->input->post('temp_firstname'),
'lastname' => $this->input->post('temp_lastname'),
'email' => $this->input->post('temp_emailid'),
'password' => password_hash($this->input->post('temp_password'), PASSWORD_DEFAULT),
'userlevel' => '3',
'organisation_id' => $this->input->post('organisation_id'),
'timestamp' => time(),
'ip' => $this->input->ip_address(),
'status' => 1,
'regdate' => time()
);
//Transfering data to Model
$this->Org_model->orgUsers($data);
$this->session->set_flashdata('success', 'User created successfully.');
//Loading View
redirect('Organisation/editOrg');
}
}
以下是我的观点:
<div class="panel-body">
<?php echo validation_errors(); ?>
<form action="<?php echo base_url(); ?>Organisation/createOrgUsers" id="user-groups-create" class="form-horizontal" method="post">
<div id="infoMessage" class="error" ><?php echo $this->session->flashdata('message'); ?></div>
<div class="form-group">
<label class="col-sm-4 control-label">Username : </label>
<div class="col-md-8">
<input type="text" name="temp_username" class="form-control" value="<?php echo set_value('temp_firstname'); ?>" />
</div>
<?php echo form_error('temp_username', '<span class="error">', '</span>'); ?>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">First Name : </label>
<div class="col-md-8">
<input type="text" name="temp_firstname" class="form-control" value="<?php echo set_value('temp_firstname'); ?>" />
</div>
<?php echo form_error('temp_firstname', '<span class="error">', '</span>'); ?>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Last Name : </label>
<div class="col-md-8">
<input type="text" name="temp_lastname" class="form-control" value="<?php echo set_value('temp_lastname'); ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Password : </label>
<div class="col-md-8">
<input type="text" name="temp_password" class="form-control" value="<?php echo set_value('temp_password'); ?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Confirm Password : </label>
<div class="col-md-8">
<input type="password" name="temp_confirm_password" class="form-control" value="" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Email Id : </label>
<div class="col-md-8">
<input type="text" name="temp_emailid" class="form-control" value="<?php echo set_value('temp_emailid'); ?>" />
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-sm-offset-4">
<input type="hidden" name="organisation_id" value="<?php echo $orgName[0]['id']; ?>">
<button type="submit" value="submit" class="btn btn-primary form-control" id="submit">Submit</button>
</div>
</div>
</form>
</div>
我不知道为什么我无法在每个字段的表单提交上看到错误消息。我正在尝试显示每个表单字段的错误消息,如果用户单击提交按钮而没有给出任何值。< / p>
任何人都可以在我错误的地方帮助我
提前致谢