<?php echo form_open($controller_name . '/save/' . $person_info->person_id, array('id'=>'customer_form', 'class'=>'form-horizontal')); ?>
.
.
.
<?php echo form_close(); ?>
<script type="text/javascript">
.
.
.
var csrf_token = function() {
return Cookies.get('<?php echo $this->config->item('csrf_cookie_name'); ?>');
};
var csrf_form_base = function() {
return { <?php echo $this->security->get_csrf_token_name(); ?> : function () { return csrf_token(); } };
};
.
.
.
//validation and submit handling
$(document).ready(function()
{
$('#customer_form').validate($.extend({
submitHandler: function(form)
{
$(form).ajaxSubmit({
success: function(response)
{
dialog_support.hide();
table_support.handle_submit('<?php echo site_url($controller_name); ?>', response);
},
dataType: 'json'
});
},
rules:
{
first_name: "required",
last_name: "required",
email:
{
remote:
{
url: "<?php echo site_url($controller_name . '/ajax_check_email')?>",
type: "post",
data: $.extend(csrf_form_base(),
{
"person_id" : "<?php echo $person_info->person_id; ?>",
// email is posted by default
})
}
},
account_number:
{
remote:
{
url: "<?php echo site_url($controller_name . '/ajax_check_account_number')?>",
type: "post",
data: $.extend(csrf_form_base(),
{
"person_id" : "<?php echo $person_info->person_id; ?>"
// account_number is posted by default
})
}
}
},
messages:
{
first_name: "<?php echo $this->lang->line('common_first_name_required'); ?>",
last_name: "<?php echo $this->lang->line('common_last_name_required'); ?>",
email: "<?php echo $this->lang->line('customers_email_duplicate'); ?>",
account_number: "<?php echo $this->lang->line('customers_account_number_duplicate'); ?>"
}
}, form_support.error));
});
$("input[name='sales_tax_code_name']").change(function() {
if( ! $("input[name='sales_tax_code_name']").val() ) {
$("input[name='sales_tax_code']").val('');
}
});
var fill_value = function(event, ui) {
event.preventDefault();
$("input[name='sales_tax_code']").val(ui.item.value);
$("input[name='sales_tax_code_name']").val(ui.item.label);
};
$("#sales_tax_code_name").autocomplete({
source: '<?php echo site_url("taxes/suggest_sales_tax_codes"); ?>',
minChars: 0,
delay: 15,
cacheLength: 1,
appendTo: '.modal-content',
select: fill_value,
focus: fill_value
});
</script>