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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?