如何接收动态文本框的post值

时间:2010-02-10 09:16:30

标签: php codeigniter

这是我的forloop,其中包含大量数据

$a = 1;
for($i = 0; $i < sizeof($StudName); $i++) { ?>
<tr align="left">
    <td class="table_label"><? echo $code[$i].' - '.$StudName[$i]; ?></td>
    <td><input type="text" name="mark1<?= $a ?>" id="mark1<?= $a ?>" ></td>
    <td><input type="text" name="mark2<?= $a ?>" id="mark2<?= $a ?>" ></td>
    <td><input type="text" name="mark3<?= $a ?>" id="mark3<?= $a ?>" onkeyup="return percent('mark1<?= $a ?>','mark2<?= $a ?>','mark3<?= $a ?>','total<?= $a ?>','Average<?= $a ?>')" ></td>
    <td><input type="text" name="total<?= $a ?>" id="total<?= $a ?>" onkeyup="return percent('mark1<?= $a ?>','mark2<?= $a ?>','mark3<?= $a ?>','total<?= $a ?>','Average<?= $a ?>')"></td>
    <td><input type = "text" name="Average<?= $a ?>" id="Average<?= $a ?>" ></td>
</tr>
<? $a++; } ?>

我收到了这样的值:

function Addmark() {

    echo "ssssssssssss";

    for($a = 1; $a <= $rowcount; $a++) {
        $markI   = 'mark1'.$a;
        $markII  = 'mark2'.$a;
        $markIII = 'mark3'.$a;
        $total   = 'total'.$a;
        $avg     = 'Average'.$a;

        echo $mI[] = $this->input->post($mark1);
        $mII[]     = $this->input->post($mark2);
        $mIII[]    = $this->input->post($mark3);
        $Total[]   = $this->input->post($total);
        $Avrg[]    = $this->input->post($Average);
    }

    $res = $this->staffModel->Addmark($mI, $mII, $mIII, $Total, $Avrg);

    if($res == true) {
        $this->session->set_flashdata('response', 'data added successfully !');
    } else {
        $this->session->set_flashdata('response', 'data already exist !');
    }

    $this->load->view('Sstudentlist',$data);
}

这是正确的语法

1 个答案:

答案 0 :(得分:1)

首先,确保在循环之前创建了form标记:

echo '<form name="frm" method="post" action="your-action-here">';

// now your loop that creates fields
for(....)
{
  echo '<input type="text" name="mark[]" value="'.$your_var.'" />';
}

// now we specify the closing `form` tag
echo '</form>';

//Now you can get the values of dynamically generated page like this in the page which you have specified in the `action attribute` of the form tag above:

$_POST['mark'];
// or you can see what it has got:
print_r($_POST['mark']);