我可以自由地单击submit按钮而不必在表单中输入值..然后在数据库中插入一行,其中的列包含零
控制器

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');
        }
    }
}

而且我的确认也不起作用
页脚视图
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);

看法
这是我的视图在我的页脚中使用id create\u exp
<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 from the right which all you need to enter for today</span>
        <!--here goes the 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>

最佳答案

因为操作人员想显示div中的所有错误

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

因为手术室想要更多的信息,
包含视图或公用页
$this->加载->查看('yourownpage');
那么您应该在yourownpage.php文件夹中有views
要进行分页,请在控制器的函数中执行此操作
$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();

注:
确保将errordiv放在不会伤害您的文本框的位置

10-05 19:29