I'm discovering twig, but despite its excellent documentation, I'm struggling on something that should be quite simple.
I'm making an edit profile page, where the user informations are pre-filled/checked.
I'm using an object User for the informations.
Basically it's very easy thanks, to twig: here's the simplified exemple of the name, e-mail, and biography field.
<input type="text" value="">
<input type="email" value="">
<textarea></textarea>
But I'm stuck in a form of checkboxes, (which are hobbies). I want them to be checked if they have been checked when the user registered.
My hobbies values are an array (user.hobbies). So it should be pretty simple, but it seems I'm struggling on the twig syntaxe (which is nevertheless very good).
Here's a exemple of the hobbies form before trying to auto-check the values:
<div class="checkbox">
<label><input type="checkbox" id="eat" name="hobbies[]" value="eat">Eat Terrans</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="hobbies[]" value="invade">Invade Aiur</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="hobbies[]" value="obey">Obey to the Overmind</label>
</div>
I've tried to loop in the user.hobbies array and compare its values with each checkboxes, and check them if there is a match.
Here's an exemple of what each checkboxes should become:
<div class="checkbox">
<label><input type="checkbox" name="hobbies[]" value="eat"
>Eat Terran</label>
</div>
But it doesn't work, because it seems I can't get the value of the checkboxes. Is "hobbies" for checkboxes name in the twig condition wrong because it's actually "hobbies[]"?
Thanks for your time,
glio
Aucun commentaire:
Enregistrer un commentaire