简体   繁体   English

Codeigniter表单验证打开空白页

[英]Codeigniter Form Validation opening blank page

I am following a tutorial on how to create a login system using Codeigniter. 我正在关注有关如何使用Codeigniter创建登录系统的教程。

I have created the following form in my view: 我在视图中创建了以下表单:

<!DOCTYPE html>
<html lang="en">

<body>

<div class="container">

    <h1>Login</h1>

<?php

    echo form_open('welcome/login_validation');

    echo validation_errors();


    echo form_label('Email: ');
    echo form_input('email'); //form_input(name,value)

    echo '<br />';

    echo form_label('Password: ');
    echo form_password('password');

    echo '<br />';

    echo form_submit('login_submit', 'Login'); //form_submit(name,value)


    echo form_close();


?>
</div>


</body>

</html>

But when I click the submit button, on google chrome, it opens a blank page with "about:blank" in the address bar. 但是,当我单击“提交”按钮时,在谷歌浏览器上,它会在地址栏中打开一个空白页面,并带有“ about:blank”。

In FireFox it has the correct address "...welcome/form_validation" but comes up with the following message: 在FireFox中,它具有正确的地址“ ... welcome / form_validation”,但显示以下消息:

"This address is restricted This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection." “此地址是受限制的。此地址使用的网络端口通常用于Web浏览以外的目的。Firefox已取消了您的保护请求。”

On Microsoft Edge, it just stays at the page with the form. 在Microsoft Edge上,它仅停留在带有表单的页面上。

Here is my Controller: 这是我的控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see http://codeigniter.com/user_guide/general/urls.html
 */
public function index()
{
    $this->login();
}

public function login()
{
    $this->load->view('login');
}

public function login_validation()
{

   $this->load->library('form_validation');

    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required|md5');


    if($this->form_validation->run()){

        redirect('main/members');


    } else{

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


    }

}


public function members()
{

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



}

}

Any help is appreciated. 任何帮助表示赞赏。 If you need anymore info, let me know and I will post it. 如果您需要更多信息,请告诉我,我将其发布。

Thanks 谢谢

Edit: I am using codeigniter 3.0.3 编辑:我正在使用codeigniter 3.0.3

Form open refers to the method in the Welcome Controller which will handle the Login Form. 表单打开是指Welcome控制器中将处理登录表单的方法。

In your view it is echo form_open('welcome/form_validation'); 您认为它是echo form_open('welcome/form_validation');

But

In your Controller it is public function login_validation() 在您的Controller中,它是public function login_validation()

Either change the view form_open action or Controller's method name 更改视图form_open操作或Controller's方法名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM