2016-06-16 120 views
0

我的頁面中有200個輸入字段。都是單選按鈕5.我怎樣才能得到輸入字段的數據。所有輸入字段的名稱都是從數據庫動態創建的。請幫幫我。從codeignitor中的輸入字段獲取所有表單數據

我的代碼如下

$attributes = array('class' => 'result', 'id' => 'result', 'name' => 'result'); 
         echo form_open('exam/result',$attributes); 
        $a = array(
          'name'   => 'aptitude-'.$value->question_id, 
          'id'   => 'answer1', 
          'value'   => 'a', 
          'checked'  => FALSE, 
         ); 
        $b = array(
          'name'   => 'aptitude-'.$value->question_id, 
          'id'   => 'answer2', 
          'value'   => 'a', 
          'checked'  => FALSE, 
         ); 
        $c = array(
          'name'   => 'aptitude-'.$value->question_id, 
          'id'   => 'answer3', 
          'value'   => 'a', 
          'checked'  => FALSE, 
         ); 
        $d = array(
          'name'   => 'aptitude-'.$value->question_id, 
          'id'   => 'answer4', 
          'value'   => 'a', 
          'checked'  => FALSE, 
         ); 
        $e = array(
          'name'   => 'aptitude-'.$value->question_id, 
          'id'   => 'answer5', 
          'value'   => 'a', 
          'checked'  => FALSE, 
         ); 
        $f = array(
          'name'   => 'aptitude-'.$value->question_id, 
          'id'   => 'answer6', 
          'value'   => 'a', 
          'checked'  => TRUE, 
          'style'   => 'display:none' 
         ); 

        echo form_radio($a); 
        echo form_label($value->a, 'a'); 
        echo "<br>"; 

        echo form_radio($b); 
        echo form_label($value->b, 'b'); 
        echo "<br>"; 

        echo form_radio($c); 
        echo form_label($value->c, 'c'); 
        echo "<br>"; 

        echo form_radio($d); 
        echo form_label($value->d, 'd'); 
        echo "<br>"; 

        echo form_radio($e); 
        echo form_label($value->e, 'e'); 
        echo "<br>"; 

        echo form_radio($f); 


        echo form_close(); 

此代碼將200次

在此先感謝

回答

1

使用數組名aptitude[]運行:

$a = array(
     'name'   => 'aptitude['.$value->question_id.']', 
     'id'   => 'answer1', 
     'value'   => 'a', 
     'checked'  => FALSE, 
    ); 
$b = array(
     'name'   => 'aptitude['.$value->question_id.']', 
     'id'   => 'answer2', 
     'value'   => 'b', 
     'checked'  => FALSE, 
    ); 
$c = array(
     'name'   => 'aptitude['.$value->question_id.']', 
     'id'   => 'answer3', 
     'value'   => 'c', 
     'checked'  => FALSE, 
    ); 
$d = array(
     'name'   => 'aptitude['.$value->question_id.']', 
     'id'   => 'answer4', 
     'value'   => 'd', 
     'checked'  => FALSE, 
    ); 
$e = array(
     'name'   => 'aptitude['.$value->question_id.']', 
     'id'   => 'answer5', 
     'value'   => 'e', 
     'checked'  => FALSE, 
    ); 
$f = array(
     'name'   => 'aptitude['.$value->question_id.']', 
     'id'   => 'answer6', 
     'value'   => 'f', 
     'checked'  => TRUE, 
     'style'   => 'display:none' 
    ); 

獲取POST值:

$aptitudes = $this->input->post('aptitude'); 

print_r($aptitudes); 

// example output 
[7] => a 
[5] => c 
[3] => f 
// where [7] [5] [3] are the $value->question_id 

獲取特定後期

$aptitudes[5]; // output => c 
相關問題