doswy02440 2015-07-11 15:18
浏览 52
已采纳

Codeigniter 3表格不发布

*UPdate, it would appear none of the forms seem to post correctly. They all load whatever URL is specified in action put no POST data is available.

My app is running fine on Lamp locally. Once uploaded to my live server the login form will not function. I am using CI3 and the Ion Auth library.

I have tried var_dump($_POST)

which always outputs the following:

array(0) {

}

So it would seem that the form is not posting. My Form:

<?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>

The post to URL is the same as the one the form is displayed on, and as I say it works fine on lamp. Firebug shows errors about password field and unsecure site but I assumed this wouldnt prevent the form from posting?

I have replaced the redirects with var_dump but nothing happens, the issue is that there is no _POST data being sent.

Controller:

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);
    }
}

The html output from the abiove controller/view:

<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>
  • 写回答

2条回答 默认 最新

  • dongqiu3709 2015-07-12 11:18
    关注

    I have now solved this and I am extremely annoyed with myself as it was a simple fix due to a config error. aren't the most brain racking problems always like this?

    Anyway for anyone else having the same issue check your site_url in config.

    Mine was set to http://www.example.com however the server redirected to http://example.com therefore using site_url to post to got redirected to the non www domain losing the post data.

    Now time to move on with what I should of spent my weekend doing.

    Thank you for everyones attempts to help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料