Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to receive the post value of dynamic text box

this is my forloop which has bulk number of data

$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++; } ?>

I received the values like this:

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);
}

is this the correct syntax

like image 379
udaya Avatar asked Nov 14 '22 12:11

udaya


1 Answers

First of all, make sure that you have created the form tag before the loop:

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']);
like image 99
Sarfraz Avatar answered Dec 14 '22 22:12

Sarfraz