[eluser]xtremer360[/eluser]
My form will validate on the client side but I'm trying to figure out why its not validating on the server side. I don't have my php complete but its not even bringing up the POST request in my console saying its submitting the form to the server.
jQuery:
Code: $(document).ready(function()
{
/*
* Validate the form when it is submitted
*/
var validateform = $("#newArticleForm").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 .content').removeAlertBoxes();
$('.box .content').alertBox(message, {type: 'warning', icon: true, noMargin: false});
$('.box .content .alert').css({
width: '100%',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
});
} else {
$('.box .content').removeAlertBoxes();
}
},
showErrors : function(errorMap, errorList) {
this.defaultShowErrors();
var self = this;
$.each(errorList, function() {
var $input = $(this.element);
var $label = $input.parent().find('label.error').hide();
$label.addClass('red');
$label.css('width', '');
$input.trigger('labeled');
$label.fadeIn();
});
},
submitHandler: function(form) {
var dataString = $('#newArticleForm').serialize();
$.ajax({
type: 'POST',
url: '/kowmanager/dashboard/articleSubmit',
data: dataString,
dataType: 'json',
success: function(data) {
if (data.error) {
$('.box .content').removeAlertBoxes();
$('.box .content').alertBox(data.message, {type: 'warning', icon: true, noMargin: false});
$('.box .content .alert').css({
width: '',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
});
}
else
{
$('.box .content').removeAlertBoxes();
$('.box .content').alertBox(data.message, {type: 'success', icon: true, noMargin: false});
$('.box .content .alert').css({
width: '',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
});
$(':input','#newArticleForm')
.not(':submit, :button, :hidden, :reset')
.val('');
}
}
});
}
});
});
Controller:
Code: function articleSubmit()
{
$outputArray = array('error' => 'yes', 'message' => 'unproccessed');
$outputMsg = '';
// Sets validation rules for the login form
$this->form_validation->set_rules('title', 'Title',
'trim|required|xss_clean|alpha_numeric');
$this->form_validation->set_rules('category', 'Category',
'integer');
$this->form_validation->set_rules('isSticky', 'Is Sticky',
'integer');
$this->form_validation->set_rules('comments', 'Allow Comments',
'integer');
// 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
{
}
}
View:
Code: <?php $attributes = array('class' => 'validate', 'id' => 'newArticleForm'); ?>
<?php echo form_open_multipart('', $attributes) ?>
<div class="content no-padding">
<div class="section _100">
<?php echo form_label('Title', 'title'); ?>
<div>
<?php echo form_input('title', '', 'class="required"'); ?>
</div>
</div>
<div class="section _100">
<?php echo form_label('Category', 'category'); ?>
<div>
<?php echo form_dropdown('category', $categories, '', 'class="required"'); ?>
</div>
</div>
<div class="section _100">
<?php echo form_label('Is Sticky', 'sticky'); ?>
<div>
<?php
$options = array(
'' => 'Please Select An Option',
'0' => 'No',
'1' => 'Yes',
);
?><?php echo form_dropdown('sticky', $options, '', 'class="required"'); ?>
</div>
</div>
<div class="section _100">
<?php echo form_
[eluser]Matalina[/eluser]
Code: <?php echo form_open_multipart('', $attributes) ?>
Where is it going?
[eluser]xtremer360[/eluser]
That's for the jQuery to handle.
[eluser]Matalina[/eluser]
your url may be wrong in your handler.
Code: url: '/kowmanager/dashboard/articleSubmit',
Not that it's common practice but I'd have a default if javascript was turned off form to go thru.
[eluser]xtremer360[/eluser]
Its not even bringing up the post request though. And its the same jquery as my other forms. I just don't see what's breaking it.
[eluser]InsiteFX[/eluser]
Code: url: <?php echo base_url();?> + 'kowmanager/dashboard/articleSubmit',
Or you can add this to your html head tag.
Code: // replace $ in script with s
<$cript type="text/javascript" charset="utf-8">
//<![CDATA[
var base_url = "<?php echo base_url(); ?>";
var site_url = "<?php echo site_url(); ?>";
// ]]>
</$cript>
url: base_url + 'kowmanager/dashboard/articleSubmit',
url: site_url + 'kowmanager/dashboard/articleSubmit',
[eluser]xtremer360[/eluser]
For some reason its not working. I'm going to send you a PM message on here.
[eluser]InsiteFX[/eluser]
Try this:
Code: url: base_url + 'dashboard/articleSubmit',
kowmanager is your directory id bet, which should be on your base_url
[eluser]xtremer360[/eluser]
Tried again and still isn't putting the POST in the console.
|