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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?