codeigniter多个ckeckbox

时间:2017-08-05 23:50:18

标签: php codeigniter checkbox

我正在尝试获取多个复选框值我得到的最后一个值总是不是全部我尝试检查它是否是数组但是它是单值

const array = [];

// these operations start at the same time
const p1 = new Promise(resolve => resolve(1));
const p2 = new Promise(resolve => resolve(2));

// no matter which one finishes first,
// we process p2 before p1 because of
// the way we build the chain
p2
.then(p2Result => {
  array.push(p2Result)
  return p1;
})
.then(p1Result => {
  array.push(p1Result);
  return array;
})
.then(console.log);

和我的控制器

    private class CustomTimer : IDisposable
    {
        private int duration = 1000;
        private Action<object> tick;
        private object obj;
        private Thread thread;
        private bool start = false;

        public CustomTimer(int duration, Action<object> tick)
        {
            this.duration = duration;
            this.tick = tick;
        }

        public void Start(object obj)
        {
            this.obj = obj;
            start = true;
            if (thread == null)
            {
                keepRunning = true;
                thread = new Thread(ThreadMethod);
                thread.Start();
            }
            else
            {
                if (thread.ThreadState == ThreadState.WaitSleepJoin)
                    thread.Interrupt();
            }
        }

        public void Stop()
        {
            if (!start)
                return;
            start = false;
            if (thread.ThreadState == ThreadState.WaitSleepJoin)
                thread.Interrupt();
        }

        public bool IsStopped
        {
            get { return !start; }
        }

        private bool keepRunning = false;
        private void ThreadMethod()
        {
            while (keepRunning)
            {
                if (start)
                {
                    try { Thread.Sleep(duration); } catch { }
                    if (start && keepRunning)
                        tick(this.obj);
                }
                else if(keepRunning)
                {
                    try { Thread.Sleep(int.MaxValue); } catch { }
                }
            }
        }



        public void Dispose()
        {
            this.keepRunning = false;
            this.start = false;
            if (thread.ThreadState == ThreadState.WaitSleepJoin)
                thread.Interrupt();
            if (thread.ThreadState == ThreadState.WaitSleepJoin)
                thread.Interrupt();
        }
    }

我希望获得所有已检查的值

3 个答案:

答案 0 :(得分:0)

在html表单上,如果您希望将输入作为数组传递,则应将其命名为数组。例如:

<input type="checkbox" name="var[]"/>

答案 1 :(得分:0)

尝试更改名称:

代替meal_cat:

<input type="checkbox" name="meal_cat" value='.$cats_id[$i].'>';

按meal_cat改变[]:

<input type="checkbox" name="meal_cat[]" value='.$cats_id[$i].'>';

在你的php中使用这个变量作为数组。

答案 2 :(得分:0)

您将输入名称作为数组传递,然后您可以使用var本身访问所有选中的复选框,这将是一个数组。

将表单中的名称设置为meal_cat[],您将能够以阵列形式访问所有复选框。

$this->input->post('meal_cat');

它将是一个数组,与$_POST['meal_cat']相同。 要打印数组:

<?php 
if (isset($_POST['meal_cat'])) 
{
    print_r($_POST['meal_cat']); 
}
?>
// OR

<?php 
if (isset($this->input->post('meal_cat'))) 
{
    print_r($this->input->post('meal_cat')); 
}
?>

如果您希望以逗号分隔的列表中的数据,那么请尝试implode

echo implode(',', $this->input->post('meal_cat'));