Tuesday, December 6, 2022
HomeWordPress Developmentphp - The right way to get information (not worth or identify)...

php – The right way to get information (not worth or identify) from radio choices to POST to database


I’ve a set of choices which might be generated primarily based on database rely. For instance, if a bunch has 4 members, 4 radio choice pairs of sure and no will present:

Identify 1

 - Attending? Sure / No

Identify 2

 - Attending? Sure / No

and many others

I am making an attempt to then get all of the names of the company who’ve clicked “sure”, they’re attending.

I can not do $_POST['radio_name'] as all radio pairings have totally different identify‘s and the worth of all of them are set to “sure”.

For instance, listed here are the fields for two company:

<?php foreach ($outcomes as $consequence){ 

  $celebration = $consequence['party']; // "John, Doe" in DB varchar 
  $party_guests = explode(",", $celebration);

  foreach ($party_guests as $index=>$visitor){ ?>

  <span class="guest__name"><?php echo $visitor; ?></span>
  <div class="guest__options-option">
    <span>Attending?</span>
    <div class="guest__options-group">
      <enter class="guest__attendance-input" id="attending-yes-<?php echo $index; ?>" kind="radio" identify="attending-<?php echo $index; ?>" worth="sure" required/>
      <label for="attending-yes-<?php echo $index; ?>">Sure</label>
    </div>
    <div class="guest__options-group">
      <enter class="guest__attendance-input" id="attending-no-<?php echo $index; ?>" kind="radio"  identify="attending-<?php echo $index; ?>" worth="no" required/>
      <label for="attending-no-<?php echo $index; ?>">No</label>
    </div>
  </div>

  <?php }
  
} ?>

As talked about, I am making an attempt to collate an inventory of all those that had mentioned sure, and no, into particular person variables so I can then push them into the database (which is a varchar, the names will probably be separated by commas).

Nevertheless, I am uncertain the best way to method this as $_POST[''] won’t work dynamically (i.e. $_POST['attending-yes-4'] won’t work if there’s solely 2 company generated).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments