php - How to insert zero rows in codeigniter -


i'm click submit button freely without enter values in form..then in database row inserted columns contain zeros

controller

function submit_expense() {     $exp_date=$this->input->post('expense_date');     $expense_ids= $this->input->post('expense');     $expense_ids=substr($expense_ids,0,strlen($expense_ids)-1);     $expense_id_array = explode(',',$expense_ids);     $id=$this->session->userdata('userid');     for($i=0;$i<count($expense_id_array);$i++)     {         $required_id = trim($expense_id_array[$i]);         $this->form_validation->set_error_delimiters('<div style="color:#b94a48">', '</div>');                                          $this->form_validation->set_rules('exp_amount_'.$required_id, 'expense amount', 'required|numeric');         $this->form_validation->set_rules('comment_'.$required_id, 'comments', 'required|alpha');         if ( $this -> form_validation -> run() === false )         {             $this->index();         }         else         {             $amount= $this->input->post('exp_amount_'.$required_id);             $comment=$this->input->post('comment_'.$required_id);             $expense_data=array(                 'expense_id'=>$required_id,                 'expense_amount'=>$amount,                 'user_id'=>$id,                 'date'=>$exp_date,                 'comments'=>$comment,             );             $this->home_model->insert_expense($expense_data);             $this->session->set_flashdata('message', 'successfully submitted.');             redirect(base_url().'home/index');         }     } } 

and validation not working

footer_view

var new_string ='<div class="form-group" id="ex_'+unqid1+'">'     +'<label for="exampleinputpassword1">'+name+'</label> </br>'     +'<input name="exp_amount_'+unqid1+'" id="id_'+unqid1+'" type="text" '+     'class="form-control" placeholder="enter '+name+' expense amount" style="margin-right:20px;" required>'     +'<input name="comment_'+unqid1+'" type="text" id="comment"  class="form-con" placeholder="comments" style="margin-right:20px;" required ></div >' ; $("#create_exp").append(new_string); 

view

this view use id create_exp in footer

<form role="form"  action="<?echo base_url()?>home/submit_expense" method="post">     <?$todays_date=date('y-m-d');?>     <input id="expense_date" name="expense_date" value="<?echo $todays_date;?>" type="hidden" />     <div class="red">         <? echo $this->session->flashdata('message'); ?>     </div>      <div class="box-body" id="create_exp">         <?php echo validation_errors(); ?>         <span>choose right need enter today</span>         <!--here goes input boxes-->         <!-- /.input boxes -->     </div><!-- /.box-body -->     <span id="errmsg1"></span>     <input id="expenseval" name="expense" type="hidden"   class="form-control">     <div class="box-footer" id="button_id">         <button type="submit" class="btn btn-primary" >submit</button>     </div> </form> 

as op wants show errors inside div

<div id="error">  <?php echo validation_errors(); ?>  </div> 

as op wants additional info,

to include view or common page

$this->load->view('yourownpage');

then should have yourownpage.php inside views folder

to have pagination, have in controller's function

$this->load->library('pagination');  $config['base_url'] = 'yourownpage';  $config['total_rows'] = 200;  $config['per_page'] = 20;  $this->pagination->initialize($config);  echo $this->pagination->create_links(); 

note :

make sure place error div in place didn't hurt textbox


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -