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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀