[英]Not returning successful form validation rules
I'm trying to figure out why my form validation run function is returning false. 我试图弄清楚为什么我的表单验证运行函数返回false。 According to the docs it says the following:
根据文档,它表示以下内容:
The run() function only returns TRUE if it has successfully applied your rules without any of them failing.
如果run()函数成功应用了您的规则而没有任何失败,则仅返回TRUE。
Here's what my rules look like: 这是我的规则:
$this->form_validation->set_rules('nicknames', 'Nicknames',
'required');
$this->form_validation->set_rules('hometown', 'Hometown',
'required');
$this->form_validation->set_rules('height', 'Height',
'required');
$this->form_validation->set_rules('Weight', 'Weight',
'required');
$this->form_validation->set_rules('manager', 'Manager',
'required|integer');
$this->form_validation->set_rules('setup', 'Setup',
'required');
$this->form_validation->set_rules('finisher', 'Finisher',
'required');
$this->form_validation->set_rules('biography', 'Biography',
'required');
Here's what the post submission runs: 这是帖子提交的运行方式:
biography Kid coming out of college getting the chance of a lifetime.
finisher Idolizer
height 5'4"
hometown Las Vegas, Nevada
manager 0
nicknames "The Quintessential Cruiserweight of KOW!"; "K-Dub"
setup That's Wondeful
submit Submit
weight 140 lbs.
http://pastebin.com/F9XeEibf
function biographySubmit()
{
$outputArray = array('error' => 'yes', 'message' => 'unproccessed');
$outputMsg = '';
// Sets validation rules for the login form
$this->form_validation->set_rules('nicknames', 'Nicknames',
'required');
$this->form_validation->set_rules('hometown', 'Hometown',
'required');
$this->form_validation->set_rules('height', 'Height',
'required');
$this->form_validation->set_rules('Weight', 'Weight',
'required');
$this->form_validation->set_rules('manager', 'Manager',
'required|integer');
$this->form_validation->set_rules('setup', 'Setup',
'required');
$this->form_validation->set_rules('finisher', 'Finisher',
'required');
$this->form_validation->set_rules('biography', 'Biography',
'required');
// Checks to see if login form was submitted properly(
if (!$this->form_validation->run())
{
$outputArray['message'] =
'There was a problem submitting the form! Please refresh the window and try again!';
}
else
{
$bioFields = array($this->input->post('nicknames'), $this->input->post('hometown'), $this->input->post('height'), $this->input->post('weight'), $this->input->post('manager'), $this->input->post('setup'), $this->input->post('finisher'), $this->input->post('biography'));
if ($this->bios->updateBiography($bioFields, $this->session->userdata('defaultRosterListID')))
{
$outputArray = array('success' => 'Yes', 'message' =>
'Biography were updated successfully!');
}
else
{
$outputArray['message'] =
'The biopgraphy was not able to be updated in the database. Please try again later!';
}
}
echo json_encode($outputArray);
}
jQuery Code: jQuery代码:
var validateform = $("#biographyForm").validate({
invalidHandler: function(form, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'You missed 1 field. It has been highlighted.'
: 'You missed ' + errors + ' fields. They have been highlighted.';
$('.box #biographyForm .content').removeAlertBoxes();
$('.box #biographyForm .content').alertBox(message, {type: 'warning', icon: true, noMargin: false});
$('.box #biographyForm .content .alert').css({
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
}).delay( 3000 ).fadeOut( 'slow' );
} else {
$('.box #biographyForm .content').removeAlertBoxes();
}
},
ignore : 'input:hidden:not(:checkbox):not(:radio)',
showErrors : function(errorMap, errorList) {
this.defaultShowErrors();
var self = this;
$.each(errorList, function() {
var $input = $(this.element);
var $label = $input.parent().find('label.error').hide();
if (!$label.length) {
$label = $input.parent().parent().find('label.error');
}
if($input.is(':not(:checkbox):not(:radio):not(select):not([type=file])')) {
$label.addClass('red');
$label.css('width', '');
$input.trigger('labeled');
}
$label.fadeIn();
});
},
errorPlacement : function(error, element) {
if(element.is(':not(:checkbox):not(:radio):not(select):not([type=file])')) {
error.insertAfter(element);
} else if(element.is('select')) {
error.appendTo(element.parent());
} else if (element.is('[type=file]')){
error.insertAfter(element.parent());
} else {
error.appendTo(element.parent().parent());
}
if ($.browser.msie) {
error.wrap('<div class="error-wrap" />');
}
},
submitHandler: function(form) {
var dataString = $('#biographyForm').serialize();
$.ajax({
type: 'POST',
url: 'biography/biographySubmit',
data: dataString,
dataType: 'json',
success: function(data) {
if (data.error) {
$('.box #biographyForm .content').removeAlertBoxes();
$('.box #biographyForm .content').alertBox(data.message, {type: 'warning', icon: true, noMargin: false});
$('.box #biographyForm .content .alert').css({
width: '',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
}).delay( 3000 ).fadeOut( 'slow' );
}
else
{
$('.box #biographyForm .content').removeAlertBoxes();
$('.box #biographyForm .content').alertBox(data.message, {type: 'success', icon: true, noMargin: false});
$('.box #biographyForm .content .alert').css({
width: '',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
}).delay( 3000 ).fadeOut( 'slow' );
}
}
});
}
});
I'm not sure if this will totally fix your problem but your form doesn't seem to have an action
. 我不确定这是否可以完全解决您的问题,但是您的表格似乎没有
action
任何action
。 It should be something like action="[your site url]/your_controller_name/biographySubmit"
. 它应该类似于
action="[your site url]/your_controller_name/biographySubmit"
。
You could use CodeIgniter's URL Helper and use this: action="<?php echo site_url("your_controller_name/biographySubmit"); ?>"
您可以使用CodeIgniter的URL Helper并使用:
action="<?php echo site_url("your_controller_name/biographySubmit"); ?>"
Without an action, the data in the form won't be passed to the biographySubmit
function within your controller. 如果不执行任何操作,则表单中的数据将不会传递到控制器中的
biographySubmit
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.