I have a list of radio buttons for guests to select whether they're attending an event or not.
A party
can have several members, so multiple yes/no options can exist on the same page.
Idea is that a person can go down the list and hit yes or no on guest attendance. I am then trying to segment out the names of those who have accepted and declined into arrays
, so I can push it to wpdb
.
I have the following that generated the radio options:
<?php
foreach ($results as $result) {
$party = $result['party']; // "John, Doe" in DB varchar
$party_guests = explode(",", $party);
$attending_array = array();
$not_attending_array = array();
foreach ($party_guests as $index => $guest){
?>
<span class="guest__name"><?php echo $guest; ?></span>
<div class="guest__options-option">
<span>Attending?</span>
<div class="guest__options-group">
<input class="guest__attendance-input" id="attending_array[<?php echo $index; ?>]" type="radio" name="attending-<?php echo $index; ?>" value="<?php echo $guest; ?>" required/>
<label for="attending-yes-<?php echo $index; ?>">Yes</label>
</div>
<div class="guest__options-group">
<input class="guest__attendance-input" id="attending_array[<?php echo $index; ?>]" type="radio" name="attending-<?php echo $index; ?>" value="<?php echo $guest; ?>" required/>
<label for="attending-no-<?php echo $index; ?>">No</label>
</div>
</div>
<?php
}
}
?>
But I cannot see a way in which I can (via PHP
) dynamically add the names to the attending_array
or not_ attending_array
?
How can I do an array_push
based on what option the user clicks on? I cannot target a specific name
because $party
may contain 2 guest, 6 guest etc.