Wednesday, April 12, 2017

Custom group variables with select in HTML

I am using Laravel Framework to do this PHP app.

I am parsing an XML from an API and the information I get is structured like this:

projectName

projectJobs- a list with jobs that I am outputting with a @foreach into a table (<td>);

I want to let the user group the jobs as he wishes. I was thinking of doing this:

    @foreach($_SESSION['workingProjects'] as $projectName=>$projectDetails)
                    <tr class="success">
                        <td> <p class="text-muted" style="font-size: 0.7em">
                                (  )</p></td>
                        <td></td>
                        <td></td>
                    @foreach($projectDetails['jobs'] as $jobName => $jobUrl)
                        <tr>
                            <td></td>
                            <td>
                                <select>
                                    <option name="group[1][][]" value="1">
                                        1
                                    </option>
                                    <option name="group[2][][]" value="2">
                                        2
                                    </option>
                                    <option name="group[3][][]" value="3">
                                        3
                                    </option>
                                    <option name="group[4][][]" value="4">
                                        4
                                    </option>
                                    <option name="group[5][][]" value="5">
                                        5
                                    </option>
                                </select>
                            </td>
                            <td>
                                <input type="checkbox" name="k1">k1</input>
                                <input type="checkbox" name="k2">k2</input>
                                <input type="checkbox" name="k3">k3</input>
                                <input type="checkbox" name="k4">k4</input>
                                <input type="checkbox" name="k5">k5</input>
                            </td>
                        </tr>

                    @endforeach
                @endforeach
                </tbody>

Having more projects, I need to have a list of projectNames which each have a list of projectJobs grouped by the select in 1-5 range.

Example:

PROJECT1 => [ GROUP1 => [ JOB1, JOB2, JOB5 ] GROUP2 => [ JOB3, JOB4 ] ];

The problem is that I only get the crsf_token() posted and I don't think this is the proper way to do it anyway.



via Alexandru Antochi

Advertisement