-1
I want, when selecting multiple checkbox, these values to be saved in an array, so that it is later saved in the database. If I leave the checkbox with the same id, as follows:
<div class="form-group">
<label style="margin-bottom: 10px"> Dias disponíveis
</label><br />
<label><input type="checkbox" name="dias" id="dias"
value="Segunda-Feira"> Segunda-Feira</label><br />
<label><input type="checkbox" name="dias" id="dias"
value="Terça-Feira"> Terça-Feira</label><br />
<label><input type="checkbox" name="dias" id="dias"
value="Quarta-Feira"> Quarta-Feira</label><br />
<label><input type="checkbox" name="dias" id="dias"
value="Quinta-Feira"> Quinta-Feira</label><br />
<label><input type="checkbox" name="dias" id="dias"
value="Sexta-Feira"> Sexta-Feira</label>
</div>
php already understands and places the marked options in the array directly after Submit using:
$chgeckboxes = $_POST['checkbox'];
Anyone can help?
Do not put ids with the same name on a page. put classes.
– Luizinho
Using classes php understands the same way and saves the values in the array?
– Arthur Oliveira
No, don’t use it
id
repeated, it makes no sense. Just add you[]
at thename
of the fields, makingname="dias[]"
. This way, PHP will receive a array with the selected days.– Woss
Got it, then I can take the ids of all the checkers?
– Arthur Oliveira
Yes, can and should.
– Woss
Thank you so much for your help, I’ll try to do it that way!!
– Arthur Oliveira
Arthur, just having an id, it is not right to put multiple ids with the same name on a page. This is done with class, because the id is unique.
– Luizinho
In that case you don’t need the id.
– Luizinho
Understood, never use ids with the same name again, I really appreciate the help!!
– Arthur Oliveira
@When you select the checkbox and select Ubmit, PHP already puts the values in an array, and that’s not right ? I didn’t quite understand your doubt.
– Leandro Lima
My question was whether I was right
– Arthur Oliveira