Skip to content Skip to sidebar Skip to footer

How To Submit Table/form With Grouping/id To Retrieve Later

I'm trying to write html5 and PHP for a form that the user can fill out. When they hit submit, I want there to be an overall evaluation category that every 5 columns are grouped u

Solution 1:

You can use array like names in your input elements like:

<tableid="bigTable"border="1"><thead><tr><thid="bandY"class="col3">Bands @263mm Y</th><thid="bandM"class="col3">Bands @263mm M</th><thid="bandC"class="col3">Bands @263mm C</th><thid="bandK"class="col3">Bands @263mm K</th><thid="Comments"class="col3">Comments</th></tr></thead><tbody><tr><td><inputname="MCBands[]"value="9214"id="MCBands"type="hidden"><td><inputname="Yevaluation[]"value=""></td>  //Row 0 Column 1
            <td><inputname="Mevaluation[]"value=""></td>  //Row 0 Column 2
            <td><inputname="Cevaluation[]"value=""></td>  //Row 0 Column 3
            <td><inputname="Kevaluation[]"value=""></td>  //Row 0 Column 4
            <td><inputname="comment[]"value=""></td>  //Row 0 Column 4
        </tr><tr><td><inputname="MCBands[]"value="9215"id="MCBands"type="hidden"><td><inputname="Yevaluation[]"value=""></td>  //Row 0 Column 1
            <td><inputname="Mevaluation[]"value=""></td>  //Row 0 Column 2
            <td><inputname="Cevaluation[]"value=""></td>  //Row 0 Column 3
            <td><inputname="Kevaluation[]"value=""></td>  //Row 0 Column 4
            <td><inputname="comment[]"value=""></td>  //Row 0 Column 4
        </tr><tr><td><inputname="MCBands[]"value="9214"id="MCBands"type="hidden"><td><inputname="Yevaluation[]"value=""></td>  //Row 0 Column 1
            <td><inputname="Mevaluation[]"value=""></td>  //Row 0 Column 2
            <td><inputname="Cevaluation[]"value=""></td>  //Row 0 Column 3
            <td><inputname="Kevaluation[]"value=""></td>  //Row 0 Column 4
            <td><inputname="comment[]"value=""></td>  //Row 0 Column 4
        </tr></tbody></table>

And on backend, you can use:

if (isset($_GET['submit'])){
    $arr = array();   
    foreach($_POST["MCBands"] as$key => $val) {
        $arr[] = array(
            "MCBands" => $_POST["MCBands"][$key],
            "Yevaluation" => $_POST["Yevaluation"][$key],
            "Mevaluation" => $_POST["Mevaluation"][$key],
            "Cevaluation" => $_POST["Cevaluation"][$key],
            "Kevaluation" => $_POST["Kevaluation"][$key],
            "comment" => $_POST["comment"][$key]
        );    //semicolon added here ~M
    }

} 

Post a Comment for "How To Submit Table/form With Grouping/id To Retrieve Later"