Piyush
Piyush

Reputation: 4007

Codeigniter validation messages in an alertbox

i am using flexi auth library. now i need to display some validation error message in alert box. How to display please help!

currently displaying like this.

if($this->form_validation->run()==FALSE)
{
        // code for error
    $data['message_type'] = 1;
    $data['message'] = 'Below fields required '; 

$this->load->view('common/message',$data)
}

Upvotes: 2

Views: 4631

Answers (1)

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

Error will throw on your view so try alert errors on view :-

<?php if(validation_errors() != false) { echo '<script>alert("Please check the error marked in red.")</script>'; }?>

or any error you want like:-

<?php if(form_error('loanamount')) { echo '<script>alert("error")</script>'; }?>

For alert an error of field try

<?php if(form_error('loanamount')) { ?> <script>alert('<?php echo form_error('loanamount');?>');</script> <?php }?>

error will be show according to seted rules like

$this->form_validation->set_rules('loanamount', 'Loan Amount', 'trim|required|xss_clean');

you are sending $data so you can alert $data variables also in alert

Upvotes: 1

Related Questions