简体   繁体   English

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

[英]CodeIgniter Simple Form Validation Return Blank Page

I'm learning PHP Codeigniter, especially on Form-Validation. 我正在学习PHP Codeigniter,尤其是在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) MyForm.php (查看)

<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): FormSuccess.php (成功页面):

<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) : 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');
            }
    }
}

If my code works, after i click submit button then it should go to Success Page (formsuccess.php) but now it return blank page. 如果我的代码有效,则在单击提交按钮后, 它应该转到成功页面 (formsuccess.php),但现在它返回空白页面。

The Form SS : 表格SS:

在此处输入图片说明

I've tried to change webserver to XAMPP , but still face same problem... 我试图将网络服务器更改为XAMPP ,但仍然面临相同的问题...

Thanks before, for your help... 之前感谢您的帮助...

After trial and error, i found solution. 经过反复试验,我找到了解决方案。 Here're my changes to code : 这是我对代码的更改:

Controller, Form.php 控制器,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 查看,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>

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

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