我的表单验证错误停止工作,它昨天还在工作,我一定是做错了什么但似乎找不到它。
当我填写用户名和电子邮件地址时,它会发送电子邮件并回显“电子邮件已发送!”。
当我只是点击注册而不填写任何信息时,它只是重定向到加载 View 的用户/注册。
controllers/user.php:
public function signup_validation() {
$this -> load -> library('form_validation');
$this -> form_validation -> set_rules('username', 'Username', 'trim|required|alpha|min_length[3]|max_length[25]');
$this -> form_validation -> set_rules('email', 'Email', 'required|trim|valid_email|is_unique[users.email]');
$this -> form_validation -> set_rules('password', 'Password', 'required|trim');
$this -> form_validation -> set_rules('cpassword', 'Retype', 'required|trim|matches[password]');
if ($this -> form_validation -> run()) {
$key = md5(uniqid());
$this -> load -> library('email', array('mailtype' => 'html'));
$this -> load -> model('users');
$this -> email -> from('', "");
$this -> email -> to($this -> input -> post('email'));
$this -> email -> subject('Confirm your account.');
$message = "<p>Thank you for signing up!</p>";
$message = "<p><a href='" . base_url() . "user/activate/$key'>Click here</a> to confirm your account.</p>";
$this -> email -> message($message);
if ($this -> users -> add_temp_user($key)) {
if ($this -> email -> send()) {
echo "The email has been sent!";
} else {
echo "Could not send the email.";
}
} else {
echo "Problem adding user to database.";
}
} else {
redirect('user/signup');
}
}
views/signup.php
<form class="form-horizontal" action="<?php echo base_url() . 'user/signup_validation'; ?>" method="post" accept-charset="UTF-8">
<?php echo validation_errors(); ?>
<div class="control-group">
<label class="control-label" for="inputEmail">Username</label>
<div class="controls">
<input name="username" type="text" id="inputUsername" placeholder="username" value="<?php echo $this -> input -> post('username'); ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input name="email" type="email" id="inputEmail" placeholder="email" value="<?php echo $this -> input -> post('email'); ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input name="password" type="password" id="inputPassword" placeholder="password" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputRetype">Retype</label>
<div class="controls">
<input name="cpassword" type="password" id="inputRetype" placeholder="retype" />
</div>
</div>
<div class="form-actions">
<input name="signup_submit" type="submit" class="btn" value="Sign up" />
</div>
</form>
我自动加载助手:
$autoload['helper'] = array('url', 'form');
.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>
最佳答案
将 $this->load->view('sign_up'); 替换为 redirect('user/signup');
当您加载 View 并且不将其重定向到加载该页面的 Controller 方法时,会显示验证错误。
关于php - CodeIgniter form_validation 不显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14922446/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格: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
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee