dongxian0320 2015-10-21 05:51
浏览 68

检查数组数据中的空数据(jquery或php)

I try to build An Automated Scoring System using Codeigniter 3.x And Jquery and have a difficult time finding the source.

Answer input method are multiple-choice and short answer or multi answer.

Like blow image

sample image

My HTML:

[CHECKBOX LIST]
<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-lg btn-default">
        <input type="checkbox"  class="input_ans" name="<?=$t->idx?>"  value="1" />1
    </label>
    <label class="btn btn-lg btn-default">
        <input type="checkbox"  class="input_ans" name="<?=$t->idx?>"  value="2" />2
    </label>
    <label class="btn btn-lg btn-default">
        <input type="checkbox"  class="input_ans" name="<?=$t->idx?>"  value="3" />3
    </label>
    <label class="btn btn-lg btn-default">
        <input type="checkbox"  class="input_ans" name="<?=$t->idx?>"  value="4" />4
    </label>
    <label class="btn btn-lg btn-default">
        <input type="checkbox"  class="input_ans" name="<?=$t->idx?>"  value="5" />5
    </label>
</div>

[INPUT TEXT LIST}
<?php 
$tagArray = explode(',',$t->EAnswer); 
$arrayCount = count($tagArray);
?>
<?php
if ($arrayCount == 1) {
    echo '<input class="form-control input-lg input_ans1" name="'.$t->idx.'" type="text">';
} else {
    for ($i=0; $i < $arrayCount; $i++) { 
        $calc_col = 12 / $arrayCount;
        echo "<div class='col-md-$calc_col col-xs-$calc_col' style='padding:5px;'>";
        echo '<input class="form-control input-lg input_ans1" name="'.$t->idx.'" type="text">';
        echo "</div>";
    }
}
?>

CHECKBOX LIST is multiple-choice Answer, INPUT TEXT LIST is short answer or multi-answer.

My Javascript:

<script>
$(".submit_answer").click(function(event){
    event.preventDefault();
    var searchIDs = $(".input_ans:checked").map(function(){
        return this.name+':'+ this.value;
    }).toArray();

    var searchIDs1 = $(".input_ans1").map(function(){
        return this.name+':'+this.value;
    }).toArray();

    bootbox.confirm("ARE YOU SUBMIT TEST?", function(result) {
        if(result) {
            var merge_sort = $.merge( $.merge([],searchIDs), searchIDs1);
            var array_data = merge_sort.toString();
            $.ajaxSettings.traditional = true;
            $.ajax({ 
                    type : "POST",
                    data : { "data" : array_data },
                    dataType: "html",
                    url : '/CONTROLLER_NAME/AAA?>',
                    success : function(msg) {
                        console.log(msg)

                        if () {
                            // error
                        } else {                        
                            /// success
                        }
                    }
            })  
        } 
    });
})

</script>

My PHP:

<?php
$data = $this->input->post('data');
$tags = explode(',',$data);

natsort($tags);

$new= [];

foreach($tags as $v) {
    $temp = explode(':', $v);
    $new[$temp[0]][] = $temp[1];
}
foreach($new as $k => $v) {
    $new[$k] = $k . ':' . implode(',', $v);
}

foreach ($new as $key) {
    $Num = strrev(strstr(strrev($key) , ':'));
    $Text = strstr($key , ':');

    if (validate data) {
        }
    else {
            //do something
        }
}

My question is How do I check validate Empty Data in Jquery or PHP? Like below image:

sample image2

I want to do check if:

$Text = strstr($key , ':');

is Empty then alert to:

alert($Num."nth data is Empty")

or

alert(please input data)
  • 写回答

1条回答 默认 最新

  • duanna3634 2015-10-21 05:56
    关注

    In php

     if(empty($text)){ echo "please input data"; // your code here
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow