2017-07-01 204 views
1

控制器: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(); ?> 

在這段代碼中我已創建有驗證碼驗證碼在那裏和電子郵件標識已經存在完美的工作形式,但是當我插入價值進入學生表。表單值將插入到數據庫中,但頁面不會在登錄頁面上重定向。現在,我想要點擊提交按鈕時,它會將值插入表中並顯示成功消息。

謝謝

+0

'

」>'爲什麼你不試試這個.. –

回答

0

View.login.php

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>"> 

    <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"/> 

</form> 
+0

什麼都沒有發生,它顯示空白頁和插入值數據庫@RishiKesh Kumar – omkara

+0

@omkara你想重定向到'login.php'頁面? –

+0

你會看到控制器我認爲問題在那裏?我試圖重定向,但它不會工作@RishiKesh庫馬爾 – omkara

0

使用

redirect('controllerName/function_name_where_you_want_to_redirect'); 

如果裏面創建一個單獨的索引()函數,這將是更好控制器僅包含

$this->load->view('view_name'); 

然後如前所述重定向到該函數。

希望它可以幫助

0

要提交你不需要傳遞任何參數在form_open()函數的形式後在同一頁上重定向。