lundi 27 mars 2017

How could I, from a table made of checkboxes, find informations about the position about the selected ones?

Some contest:

I have three tables in my database in MySQL, names are in italian.

  • "Attivita" (activity)
  • "Ambito" (scope)
  • An associative table of the two called "Azione" (action)

"Attività" and "Ambito" have each ones just two columns: ID and NOME. "Azione" has three foreign keys. One on the ID column of "Ambito", one of the ID column of "Attività" and one to a ID column of another table, that would auto-increment by 1 each time the "Submit" button is pushed and cointains other kind of informations. What I want to do, is to make a form where the user could populate che table "Azione" by selecting as many combination of "Attività" and "Ambito" as he like.

What I have done:

I made a dynamic table full of checkpoints with the rows coming from the table "Ambito" and the columns coming from "Attività" that looks like this:

 _ | 1 | 2 | 3 | 4 | 5 |
 a |   |   |   |   |   |
 b |   |   |   |   |   |
 c |   |   |   |   |   |
 d |   |   |   |   |   |

Where the user could select many checkboxes in it, like this:

 _ | 1 | 2 | 3 | 4 | 5 |
 a |   |   |   |   |   |
 b |   | x |   | x |   |
 c |   | x |   |   |   |
 d |   | x |   |   |   |

This is the code for this form for both the tamplate page and the code page in Smarty:

Template:

     <form name="{$formName}" id="inserisciazioni" method="{$formMethod}" action="{$formAction}" class="form_standard">
            <table>
                <tr>
                    <td></td>
                    {section name=attivita loop=$fAttivitaList}
                        <td>{$fAttivitaList[attivita].descrizione}</td>
                    {/section}
                </tr>
                {section name=ambito loop=$fAmbitoList}
                    <tr> 
                        <td>{$fAmbitoList[ambito].descrizione}</td>
                        {section name=attivita loop=$fAttivitaList}
                            <td><input type="checkbox" name="cbamb" class="cbAzione" id="{$servizi[key].nome}" value="{$servizi[key].nome}" /> </td>
                        {/section}

                    </tr>
                {/section}
            </table>
            <input name="{$btnSubmitName}" id="submitBtnInter" type="submit" class="default_submit" value="Invia" />
        </form>

"Logic code" page:

$listATT = new AttivitaList($db);
$listaAttivita = array();
for ($listATT->start(); !$listATT->isAfter(); $listATT->forth()) {
$rt = array('id' => $listATT->item()->getId(), 'descrizione' => $listATT->item()->getNome());
$listaAttivita[] = $rt;
}
$smarty->assign("fAttivitaList", $listaAttivita);

$listAMB = new AmbitoList($db);
$listaAmbito = array();
for ($listAMB->start(); !$listAMB->isAfter(); $listAMB->forth()) {
$rt = array('id' => $listAMB->item()->getId(), 'descrizione' => $listAMB->item()->getNome());
    $listaAmbito[] = $rt;
}
$smarty->assign("fAmbitoList", $listaAmbito);

What I want to do:

I want to find a way to know which checkboxes of the table are selected and which not, by finding informations about their position for both the row "Ambito" and the column "Attivita".

So, I could then add as many rows in "Azione" as many checkboxes are selected.




Aucun commentaire:

Enregistrer un commentaire