2015-07-11 116 views
1

*更新,它會出現沒有任何形式似乎正確發佈。它們全部加載任何指定的URL,不要使用POST數據。Codeigniter 3表單不張貼

我的應用在本地燈上運行良好。一旦上傳到我的實時服務器,登錄表單將不起作用。我正在使用CI3和Ion Auth庫。

我已經試過 var_dump($_POST)

總是輸出以下:

array(0) { 

}

所以它似乎是形式不張貼。我的表單:

<?php echo form_open("auth/login");?> 
           <div class="form-group"> 
            <div class="input-group"> 
             <span class="input-group-addon"><i class="fa fa-user"></i> 
             </span> 
             <?php echo form_input($identity);?> 
            </div> 
           </div> 
           <div class="form-group"> 
            <div class="input-group"> 
             <span class="input-group-addon"><i class="fa fa-lock"></i> 
             </span> 
             <?php echo form_input($password);?> 
            </div> 
           </div> 
           <button type="submit" class="btn btn-primary text-theme-xs mr-8">Login</button> 
           <?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?> 
           <a href="<?= site_url('auth/forgot_password') ?>" class="text-theme-xs pull-right a-black">Forgot your password ?</a> 
          </form> 

到URL的帖子與表單顯示的一樣,正如我說的,它在燈上工作正常。 Firebug顯示有關密碼字段和不安全網站的錯誤,但我認爲這不會阻止表單發佈?

我用var_dump替換了重定向,但沒有任何反應,問題是沒有_POST數據被髮送。

控制器:

function login() 
{ 
    $this->data['title'] = "Login"; 

    //validate form input 
    $this->form_validation->set_rules('identity', 'Identity', 'required'); 
    $this->form_validation->set_rules('password', 'Password', 'required'); 

    if ($this->form_validation->run() == true) 
    { 
     //check to see if the user is logging in 
     //check for "remember me" 
     $remember = (bool) $this->input->post('remember'); 

     if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) 
     { 
      //if the login is successful 
      //redirect them back to the home page 
      $this->session->set_flashdata('message', $this->ion_auth->messages()); 
      redirect('/', 'refresh'); 
     } 
     else 
     { 
      //if the login was un-successful 
      //redirect them back to the login page 
      $this->session->set_flashdata('message', $this->ion_auth->errors()); 
      redirect('auth/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries 
     } 
    } 
    else 
    { 
     //the user is not logging in so display the login page 
     //set the flash data error message if there is one 
     $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); 

     $this->data['identity'] = array('name' => 'identity', 
      'id' => 'identity', 
      'type' => 'text', 
          'class' => 'form-control', 
      'value' => $this->form_validation->set_value('identity'), 
          'placeholder' => 'Username', 
     ); 
     $this->data['password'] = array('name' => 'password', 
      'id' => 'password', 
      'type' => 'password', 
          'class' => 'form-control', 
          'placeholder' => 'Password', 
     ); 
        $this->_render_page('templates/head', $this->data); 
     $this->_render_page('templates/navbar', $this->data); 
        $this->_render_page('auth/login', $this->data); 
        $this->_render_page('templates/footer', $this->data); 
    } 
} 

從abiove控制器/視圖的HTML輸出:

<form action="http://www.mydomain.uk/auth/login" method="post" accept-charset="utf-8"> 

    <p> 
    <label for="identity">Email/Username:</label> <input type="text" name="identity" value="" id="identity" class="form-control" placeholder="Username" /> 
    </p> 

    <p> 
    <label for="password">Password:</label> <input type="password" name="password" value="" id="password" class="form-control" placeholder="Password" /> 
    </p> 

    <p> 
    <label for="remember">Remember Me:</label> <input type="checkbox" name="remember" value="1" id="remember" /> 
    </p> 


    <p><input type="submit" name="submit" value="Login" /> 
</p> 

</form> 
+0

你有形式'action'設置是否正確? –

+0

向我們展示您的控制器代碼也在主帖子中,並在使用'<?php echo base_url('auth/login');?>'或index.php'<?php echo base_url('index.php/auth /登錄');?>'確保url助手自動加載。 http://www.codeigniter.com/user_guide/libraries/form_validation.html – user4419336

+0

我使用form_open('auth/login')我將在上面發佈控制器。它是標準的離子認證控制器。 – Philwn

回答

0

我現在已經解決了這一點,我對自己非常惱火,因爲這是一個簡單的解決由於一個配置錯誤。是不是像這樣總是最頭疼的問題?

無論如何,任何人都有相同的問題檢查您的site_url在配置。

礦被設置爲http://www.example.com但是服務器重定向到http://example.com,因此使用site_url發佈以被重定向到非www域失去發佈數據。

現在是時候繼續我應該花費我週末的時間了。

感謝您對大家的努力,以幫助

0

嘗試啓用的Apache2 mod_rewrite的模塊