控制器:test.php的頁面在提交時不在相同頁面上重定向?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url', 'captcha'));
$this->load->model('Fetch_data');
$this->session->set_flashdata('');
}
public function login()
{
if($this->input->post('signup'))
{
$data = array(
'firstname' => $this->input->post('fname'),
'lastname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('mobile'),
'city' => $this->input->post('city'),
'interest_field' => $this->input->post('interest_field'),
'password' => $this->input->post('password')
);
$this->db->select('*');
$this->db->from('students');
$where = "email = '".$this->input->post('email')."'";
$this->db->where($where);
$query = $this->db->get();
if ($query->num_rows() > 1)
{
$this->session->set_flashdata('message', '<p style="color: red;font-weight: bold;">Email Id already exist. Please login with diffrent email id.</p>');
}
else
{
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if($inputCaptcha === $sessCaptcha)
{
return $this->db->insert('students',$data);
$this->session->set_flashdata('message', '<p style="color: #89c343;font-weight: bold;">Successfull.</p>');
}
else
{
$this->session->set_flashdata('message', '<p style="color: red;font-weight: bold;">Captcha code was not match, please try again.</p>');
}
}
}
$config = array(
'img_path' => 'resources/img/captcha_images/',
'img_url' => base_url().'resources/img/captcha_images/',
'img_width' => '200',
'img_height' => 40,
'word_length' => 8,
'font_size' => 16
);
$captcha = create_captcha($config);
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode',$captcha['word']);
$data['captchaImg'] = $captcha['image'];
$this->load->view('login',$data);
}
}
觀點:login.php中
<?php echo form_open(base_url('index.php/')."test/login");?>
<input type="text" name="fname" id="fname" placeholder="Your First Name" class="text-line"/>
<input type="text" name="email" id="email" placeholder="Your Email" class="text-line"/>
<input type="text" name="mobile" id="mobile" placeholder="Your Mobile" class="text-line"/>
<p id="captImg"><?php echo $captchaImg; ?></p>
<input type="text" name="captcha" value="" class="captcha" placeholder="Enter Image Inputs"/>
<a href="javascript:void(0);" class="refreshCaptcha" >Can't Read Please Refersh Image</a>
<input type="submit" name="signup" id="signup" value="Sign Up" class="btn btn-warning"/>
<?php echo form_close(); ?>
在這段代碼中我已創建有驗證碼驗證碼在那裏和電子郵件標識已經存在完美的工作形式,但是當我插入價值進入學生表。表單值將插入到數據庫中,但頁面不會在登錄頁面上重定向。現在,我想要點擊提交按鈕時,它會將值插入表中並顯示成功消息。
謝謝
'