【发布时间】:2016-03-13 00:52:16
【问题描述】:
我正在学习 PHP Codeigniter,尤其是在表单验证方面。我所有的源代码都是从their website 复制粘贴的,没有任何改变(只是复制粘贴)。这个表单验证看起来很简单,但是每次我点击“提交按钮”然后出现空白页。代码是:
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(成功页面):
<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>
和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');
}
}
}
如果我的代码有效,在我点击提交按钮后,它应该会转到成功页面(formsuccess.php),但现在它返回空白页面。
SS 表格:
我尝试将 webserver 更改为 XAMPP,但仍然遇到同样的问题...
感谢您的帮助...
【问题讨论】:
-
你是从服务器运行 php,比如 wamp?
-
@Victoria 是的,我正在使用 wamp 运行 php...
-
把你的文件名改成
form.php -
如果你使用 CI 是哪个版本??
-
@Saty,我试过了,但还是失败了。我正在使用 CI 3.0 和 WAMP 2.5
标签: php html codeigniter