似乎无法在代码点火器上进行表单验证,不确定是什么问题!
这是我的控制器类:
class registerController extends MY_Controller {
// --- Methods -----------------
function __construct()
{
parent::__construct();
$this->firePHP->log('REGISTER PAGE CONTROLLER ACTIVE');
//Load user model
$this->load->model('usersModel');
//load form validation
$this->load->helper('form');
$this->load->library('form_validation');
}
//------------------------------
public function register()
{
$this->form_validation->set_rules('registerForenameFieldName', 'Fist Name', 'required');
//This is executed when the form is submitted
if ($this->form_validation->run() == FALSE)
{
$this->firePHP->log('Registration form validation Failed');
//Load in the views
$this->load->view('global/head.PHP');
$this->load->view('global/top.PHP');
$this->load->view('register/register.PHP');
$this->load->view('global/footer.PHP');
} else {
$this->firePHP->log('Registration form validation succeeded');
//Model method here
//Load in the views
$this->load->view('global/head.PHP');
$this->load->view('global/top.PHP');
$this->load->view('home.PHP');
$this->load->view('global/footer.PHP');
}
}
}
和我的形式:
<?PHP echo form_open('register'); ?>
<div id="registerErrors"><?PHP echo validation_errors(); ?></div>
<table id="registerTable">
<tr>
<td class="regLeftCell"><p>First Name</p></td>
<td class="regRightCell">
<input id="registerForenameField" class="textField registerField" name="registerForenameFieldName" type="text" placeholder="Forename" value="<?PHP echo set_value('registerForenameFieldName'); ?>"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Last Name</p></td>
<td class="regRightCell">
<input id="registerSurnameField" class="textField registerField" name="registerSurnameFieldName" type="text" placeholder="Surname" value="<?PHP echo set_value('registerSurnameFieldName'); ?>"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Email Address</p></td>
<td class="regRightCell">
<input id="registerEmailField" class="textField registerField" name="registerEmailFieldName" type="text" placeholder="Email Address"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Choose Password</p></td>
<td class="regRightCell">
<input id="registerPasswordField" class="textField registerField" name="registerPasswordFieldName" type="text" placeholder="Password"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Confirm Password</p></td>
<td class="regRightCell">
<input id="registerConfirmPasswordField" class="textField registerField" name="registerConfirmPasswordFieldName" type="text" placeholder="Confirm Password"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Address Line 1</p></td>
<td class="regRightCell">
<input id="registeraddress1Field" class="textField registerField" name="registeraddress1FieldName" type="text" placeholder="Address Line 1"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Address Line 2</p></td>
<td class="regRightCell">
<input id="registeraddress2Field" class="textField registerField" name="registeraddress2FieldName" type="text" placeholder="Address Line 2"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Address Line 3</p></td>
<td class="regRightCell">
<input id="registeraddress3Field" class="textField registerField" name="registeraddress3FieldName" type="text" placeholder="Address Line 3"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Post Code</p></td>
<td class="regRightCell">
<input id="registeraddresspostCodeField" class="textField registerField" name="registerPostCodeFieldName" type="text" placeholder="Post Code"></input>
</td>
</tr>
<tr>
<td class="regLeftCell"><p>Country</p></td>
<td class="regRightCell">
<input id="registeraddressCountryField" class="textField registerField" name="registerSurnameFieldName" type="text" placeholder="Country"></input>
</td>
</tr>
</table>
<div id="registerButton">
<input class="button registerSubmitButton" type="submit" value="Register"/>
</div>
</form>
路由设置如下:
$route['register'] = 'registerController/register';
它只是重新加载相同的页面,没有验证错误.每次$this-> form_validation-> run()的计算结果为FALSE,因为我已将其记录在FirePHP中,即Firebug扩展名.
编辑:
值得一提的是,尽管加载了页面,我在控制台中出现了404错误:
解决方法:
我终于找到了答案!我的服务器配置不正确,我没有启用mod_rewrite,所以没有任何请求正常工作或其他东西.
Ubuntu用户在命令行上启动它以启用它:
sudo a2enmod重写
然后重启Apache.
我使用以下.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.PHP controller,
#prevIoUsly this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$/index.PHP?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$/index.PHP?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$/index.PHP?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.PHP, and everything works as normal.
ErrorDocument 404 /index.PHP
</IfModule>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。