Codeigniter表格空检查使用Ajax提交

时间:2018-01-17 08:17:05

标签: php jquery html ajax codeigniter

我需要在提交表单时进行验证,并且没有任何有关提示消息的值,'您的字段为空'。 请帮助我。 感谢



Function load_pagination_content() {
        $('.dt_glo_loader').attr('src', base_url+'images/loading-file/loading.gif');
        $(".dt_glo_loader").show();  
        $.ajax({
            url: '<?php echo base_url("apps/blr/get_blr_pagi"); ?>',
            type: 'POST',
            data: $("#frm_blr_home").serialize(),
        })
        .done(function( respond ) {
            $("#tableBody").html( respond );
            console.log("success");
			
			var myDiv = document.getElementById('scroll_top');
			var intElemScrollTop = myDiv.scrollTop;
			myDiv.scrollTop = 0;
			
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {

			$('.popover-source2').popover();

            $('.dt_glo_loader').attr('src');
            $(".dt_glo_loader").hide(); 
        }); 
    }
&#13;
<form method="post" action="" id="frm_blr_home">
   Court Division :
   <select name="court_division_id" class="court_division_id class-select2 foucus_color" style="width:155px !important" id="court_division_id" />
      <option value=" ">Select Court Division</option>
      <option value="">All</option>
      <?php foreach($court_division->result() as $row){?>
      <option class="foucus_color" value="<?php echo $row->id; ?>"><?php echo $row->name; ?></option>
      <?php } ?>
   </select>
   &nbsp; Case Type : 
   <?php ?> 
   <select name="case_type_id" style="width:205px !important" class="case_type_id class-select2" id="case_type_id">
      <option value=" ">Select Case Type</option>
      <option value="">All</option>
      <?php foreach($case_type->result() as $row){?>
      <option value="<?php echo  $row->id; ?>"><?php echo $row->name; ?></option>
      <?php }  ?>
   </select>
   <?php ?> 
   &nbsp;Hon'ble Justice Name : 
   <select name="justice_id" class="justice_id class-select2" style="width:225px !important" id="justice_id">
      <option value=" ">Select Justice Name</option>
      <option value="">All</option>
      <?php foreach($justies_name->result() as $row){?>
      <option value="<?php echo $row->id; ?>"><?php echo $row->name; ?></option>
      <?php } ?>
   </select>
   <input type="hidden" class="mhid" name="mhid" value="<?php echo $mhid; ?>" />
   <input type="hidden" class="cdid" name="cdid" value="<?php echo $cdid; ?>" />
   <input type="hidden" class="pageno" id="pagenoid" name="pageno" value="1" /> 
   <br>
   Case No. : <input type="text" name="case_no" style="width:95px !important;" class="case_no foucus_color" placeholder=" Case No." id="case_no" required value="<?php echo set_value('case_no',''); ?>"/>
   Parties : <input type="text" name="parties" style="width:200px !important;" class="parties foucus_color" placeholder=" Parties" id="" required value="<?php echo set_value('parties',''); ?>"/>
   Section : <input type="text" name="under_section" style="width:95px !important;" class="under_section foucus_color" placeholder=" Section" id="" required value="<?php echo set_value('under_section',''); ?>"/>
   Article : <input type="text" name="article" style="width:95px !important;" class="article foucus_color" placeholder=" Article" id="" required value="<?php echo set_value('article',''); ?>"/>
   Order/Rule : <input type="text" name="order_rule" style="width:95px !important;" class="order_rule foucus_color" placeholder=" Order/Rule" id="" required value="<?php echo set_value('order_rule',''); ?>"/><br>
   Order/Judgment Date : <input type="text" name="judgment_date" style="width:90px !important;" class="judgment_date foucus_color" placeholder="dd-mm-yyyy" id="" required value="<?php echo set_value('judgment_date',''); ?>"/>
   Reference : <input type="text" name="short_description" style="width:220px !important;" class="short_description foucus_color" placeholder=" Reference" id="" required value="<?php echo set_value('short_description',''); ?>"/>
   Search by : <input type="text" name="any_words" class="any_words foucus_color" style="width:295px !important;" placeholder=" Any Word, Any Matter, Any Section or Any Sentence" id="any_words" required value="<?php echo set_value('any_words',''); ?>"/>
   </div>
   <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2" style="padding:0px; margin-left:-30px; width:15%;">
      <h4> 
         <span style="color: #F00;">Total Found&nbsp:&nbsp;<span id="showtotalPage"></span> 
         </span>
      </h4>
      </br>
      <button type="button" class="btn btn-success btn-sm btn_middle" id="button_blr_home">Search</button>&nbsp;
      <button type="button" class="btn btn-danger btn-sm btn_middle" id="case_list2">Clear</button>
      <button type="button" style="display:none;" id="button_blr_home_hidden">Search 2</button>
</form>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

尝试这个。

<script>

$(document).ready(function(){
    $("#frm_blr_home").submit(function(){
        if($("#case_no").val() == ""){
            alert('Your case no is empty.');
            return false;
        }
    });
});

</script>