似乎无法在 code igniter 上进行表单验证,不确定哪里出了问题!
这是我的 Controller 类:
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>
关于php - CodeIgniter 表单验证不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11493479/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo