【问题标题】:Codeigniter 3 form not postingCodeigniter 3 表单未发布
【发布时间】:2015-07-11 15:18:35
【问题描述】:

*UPdate,似乎没有一个表格似乎正确发布。它们都会加载任何指定的 URL,但没有可用的 POST 数据。

我的应用在本地 Lamp 上运行良好。一旦上传到我的实时服务器,登录表单将不起作用。我正在使用 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>

【问题讨论】:

  • action 的表单设置是否正确?
  • 向我们展示您的控制器代码也在主帖和行动中使用&lt;?php echo base_url('auth/login');?&gt; 或index.php &lt;?php echo base_url('index.php/auth/login');?&gt; 确保自动加载url 助手。 codeigniter.com/user_guide/libraries/form_validation.html
  • 我使用 form_open('auth/login') 我将在上面发布控制器。它是标准的离子认证控制器。
  • 我认为您的表单输入错误
  • FWIW,我正在使用带有 Ion Auth 的 CI 3,完全没有问题。我也认为您发布的代码没有任何问题。如果你让它在本地工作,那么你必须假设问题出在你的服务器上。无论控制器函数或 URL 是什么,AFAIK,你仍然应该有一个 POST 数组。

标签: php codeigniter ion-auth codeigniter-3


【解决方案1】:

我现在已经解决了这个问题,我对自己非常恼火,因为由于配置错误,这是一个简单的修复。最伤脑筋的问题不都是这样的吗?

无论如何,对于遇到相同问题的其他人,请检查配置中的 site_url。

我的设置为http://www.example.com,但服务器重定向到http://example.com,因此使用site_url 发帖被重定向到丢失帖子数据的非www 域。

现在该继续我周末应该做的事情了。

感谢大家的帮助

【讨论】:

    【解决方案2】:

    尝试启用 apache2 mod_rewrite 模块

    【讨论】:

      猜你喜欢
      • 2012-04-02
      • 1970-01-01
      • 2018-03-19
      • 2013-04-10
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      相关资源
      最近更新 更多