1

我正在尝试构建一个简单的登录表单,如此youtube 视频中所示。在视频中显示我的登录表单应该发布信息而不是获取信息,正如您在制造商重定向到的 url 中看到的那样。

但是,我的 CodeIgniter 在提交我的登录信息并被重定向到以下示例链接后总是获取信息:

http://localhost/CodeIgniter/?email=member%40backupbull.com&password=password13&login_submit=Login

表单助手会自动加载到 CodeIgniter 中。

控制器:

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('pages/members');
    } else {
        $this->load->view('login');
    }

}

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

查看(login.php):

<?php $this->load->view('site_template/header.php'); ?>
<body>
    <!--[if lt IE 7]>
        <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
    <![endif]-->

    <!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->

    <?php $this->load->view('site_template/navigation.php'); ?>

    <div class="container">

        <!-- Main hero unit for a primary marketing message or call to action -->
        <div class="hero-unit">
            <h1>Hello, world!</h1>
            <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
            <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
        </div>

        <!-- Example row of columns -->
        <div class="row">
            <div class="span4">
                <h2>Heading</h2>
                <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                <p><a class="btn" href="#">View details &raquo;</a></p>
            </div>
            <div class="span4">
                <h2>Heading</h2>
                <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                <p><a class="btn" href="#">View details &raquo;</a></p>
           </div>
            <div class="span4">
                <h2>Heading</h2>
                <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
                <p><a class="btn" href="#">View details &raquo;</a></p>
            </div>
        </div>

        <hr>
<?php $this->load->view('site_template/footer.php'); ?>

在 login.php 视图中加载的视图 (navigation.php):

<div class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container">
                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
                <a class="brand" href="#"><?php echo SITE_NAME; ?></a>
                <div class="nav-collapse collapse">
                    <ul class="nav">
                        <li class="active"><a href="#">Home</a></li>
                        <li><a href="<?php echo base_url(); ?>pages/features">Features</a></li>
                        <li><a href="<?php echo base_url(); ?>pages/pricing">Pricing</a></li>
                        <li><a href="<?php echo base_url(); ?>pages/about_us">About Us</a></li>
                        <li><a href="<?php echo base_url(); ?>pages/contact">Contact</a></li>
                        <!--
                            <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                                <li class="divider"></li>
                                <li class="nav-header">Nav header</li>
                                <li><a href="#">Separated link</a></li>
                                <li><a href="#">One more separated link</a></li>
                            </ul>
                        </li>
                        -->
                    </ul>
                    <form class="navbar-form pull-right">
                        <?php

                            echo form_open('pages/login_validation');

                            echo validation_errors();
                            echo'<p>';
                            echo form_input('email', 'member@backupbull.com');
                            echo'</p>';

                            echo'<p>';
                            echo form_password('password', 'password');
                            echo'</p>';

                            echo'<p>';
                            echo form_submit('login_submit', 'Login');
                            echo'</p>';

                            echo form_close();
                        ?>

                        <!--<input class="span2" type="text" placeholder="Email">
                        <input class="span2" type="password" placeholder="Password">
                        <button type="submit" class="btn">Sign in</button>-->
                    </form>
                </div><!--/.nav-collapse -->
            </div>
        </div>
    </div>

.htaccess 在根目录:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /BackupBull/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule> 

我不知道如何解决这个问题。

提前感谢您的帮助!

4

3 回答 3

3

form_open()功能在表单标签之间。

<form class="navbar-form pull-right"> <!-- getting submitted with the default GET method -->
    <?php
       echo form_open('pages/login_validation');
          //form inputs
       echo form_close();
    ?>
</form>

因此,提交的表单是外部表单。

删除那些表单标签,它应该可以工作。

于 2013-06-21T12:50:01.097 回答
1

form_open创建一个<form>标签(使用 POST 方法),但您在它前面加上:

<form class="navbar-form pull-right">

这个没有方法属性,这使得它默认为 GET。

于 2013-06-21T12:45:27.443 回答
0

你好试试这个强制POST

echo form_open('pages/login_validation', array('method'=> 'POST'));
于 2013-06-21T12:41:22.423 回答