我编写的代码检查用户是否在DB中拥有所有必需的信息。如果用户有,则不执行任何操作,但如果用户为空则重定向到continueregistration
页面。但是当它重定向时,就会写出
此页面无效
localhost重定向了你太多次了。尝试清除您的cookie。 ERR_TOO_MANY_REDIRECTS
我清除了我的缓存它没有用。以下是我的观点:
<?php
if($this->session->userdata('logged_in')) {
$query = $this->db->get_where('instructors', array('id' => $this->session->userdata('id')));
$insdatacheck = $query->row_array();
if($insdatacheck['name'] == '') {
redirect('/user/continueregistration/');
} else { ?>
<script type="text/javascript">alert('hello');</script>
<?php
}
}
?>
和控制器:
function continueregistration() {
//set validation rules
$this->form_validation->set_rules('name', 'name', 'trim|required|alpha|min_length[2]|max_length[30]');
$this->form_validation->set_rules('web', 'web adress', 'trim|required|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('facebook', 'facebook adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('twitter', 'twitter adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('youtube', 'youtube adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('instagram', 'instagram adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('tel', 'telephone number', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]');
$this->form_validation->set_rules('address', 'address', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]');
$this->form_validation->set_rules('insdescription', 'description', 'trim|required|alpha_numeric_spaces|min_length[3]');
$data['title'] = 'Continue Registration';
$data['instructors'] = $this->single_instructor_model->get_instructor_info();
$this->load->view('templates/header');
$this->load->view('registration/registration', $data);
$this->load->view('templates/footer');
//validate form input
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('templates/header');
$this->load->view('registration/registration', $data);
$this->load->view('templates/footer');
}
else
{
//insert the user registration details into database
$dataforreg = array(
'name' => $this->input->post('name'),
'web' => $this->input->post('web'),
'fb' => $this->input->post('facebook'),
'twitter' => $this->input->post('twitter'),
'youtube' => $this->input->post('youtube'),
'instagram' => $this->input->post('instagram'),
'phone' => $this->input->post('tel'),
'address' => $this->input->post('address'),
'description' => $this->input->post('insdescription')
);
// insert form data into database
if ($this->user_model->updateUser($dataforreg, $to_email)) {
redirect('homepage/index');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Error</div>');
redirect('user/continueregistration');
}
}
}
答案 0 :(得分:0)
我认为您符合&#34;确认表格重新提交&#34;信息。它发生在您的用户不可用时。它指向用户/继续注册,您只需重定向而不刷新,然后将数据发送到datebase并继续重定向。为此,您应该设置:重定向(&#39;链接&#39;,&#39;刷新&#39;);并确认提交按钮,如果已单击,则执行内部操作。
if(isset($_POST['submit']) //button with the name "submit"
{
//action
}