douzai3399 2015-12-08 07:22
浏览 51
已采纳

CodeIgniter简单表单验证返回空白页面

I'm learning PHP Codeigniter, especially on Form-Validation. All of my source code are copy pasted from their website and nothing changed (it just copy-paste). This Form Validation seems pretty simple, However every time i click the "submit button" then appear blank page. The Codes are :

MyForm.php (View)

<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
<input type="text" name="username" value="" size="50" />

<h5>Password</h5>
<input type="text" name="password" value="" size="50" />

<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />

<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />

<div><input type="submit" value="Submit" /></div>

</form>

</body>
</html>

FormSuccess.php (Success Page):

<html>
<head>
<title>My Form</title>
</head>
<body>

<h3>Your form was successfully submitted!</h3>

<p><?php echo anchor('form', 'Try it again!'); ?></p>

</body>
</html>

And Form.php (Controller) :

<?php

class Form extends CI_Controller {

    public function index()
    {
            $this->load->helper(array('form', 'url'));

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

            $this->form_validation->set_rules('username', 'Username', 'required');
            $this->form_validation->set_rules('password', 'Password', 'required',
                    array('required' => 'You must provide a %s.')
            );
            $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
            $this->form_validation->set_rules('email', 'Email', 'required');

            if ($this->form_validation->run() == FALSE)
            {
                    $this->load->view('MyForm');
            }
            else
            {
                    $this->load->view('FormSuccess');
            }
    }
}

If my code works, after i click submit button then it should go to Success Page (formsuccess.php) but now it return blank page.

The Form SS :

enter image description here

I've tried to change webserver to XAMPP, but still face same problem...

Thanks before, for your help...

  • 写回答

1条回答 默认 最新

  • douhuan2101 2015-12-10 04:52
    关注

    After trial and error, i found solution. Here're my changes to code :

    Controller, Form.php

    <?php
    
    class Form extends CI_Controller {
    
        public function index()
        {
            $this->load->helper(array('form', 'url'));
    
            $this->load->library('form_validation');
    
            $this->form_validation->set_rules('username', 'Username', 'required');
            $this->form_validation->set_rules('password', 'Password', 'required',
                    array('required' => 'You must provide a %s.')
            );
            $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
            $this->form_validation->set_rules('email', 'Email', 'required');
    
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('myform');
            }
            else
            {
                $this->load->view('formsuccess');
            }
        }
    }
    ?>
    

    View, MyForm.php

    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <title>My Form</title>
    </head>
    <body>
    
    <?php echo validation_errors(); ?>
    
    <form action="<?php base_url();?>form" method="POST">
    
    <h5>Username</h5>
    <input type="text" name="username" value="" size="50" />
    
    <h5>Password</h5>
    <input type="text" name="password" value="" size="50" />
    
    <h5>Password Confirm</h5>
    <input type="text" name="passconf" value="" size="50" />
    
    <h5>Email Address</h5>
    <input type="text" name="email" value="" size="50" />
    
    <div><input type="submit" value="Submit" /></div>
    
    </form>
    
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?