Jump to content

seperate grouped radio button for each photo - keep/delete options


Go to solution Solved by Barand,

Recommended Posts

I have not used radio buttons but a long time.

I wish to have an approve page show the images with keep or delete radio buttons underneath.  There would be a few images showing at any one time waiting to be checked.  I do not need a default selection for any as they admins can leave them and check again another time.

<div class="floatLeft">
<img class="maxwidth" src="uploads/S<?php echo($result['img_name']); ?>">
</div>
<div class="floatLeft">&nbsp;&nbsp;<strong>Username:</strong><?php echo(htmlentities($result['user_name'])); ?></div><br>
<div class="floatLeft">&nbsp;&nbsp;<strong>Description:</strong> <?php echo($result['description']); ?></div><br>
<div class="floatLeft">&nbsp;&nbsp;<?php echo($result['created']); ?></div><br>
<div class="clearFloat"></div>
<div class="floatLeft"><input type="radio" name="list[]" value="<?php echo($result['id']); ?>">Approve</div>
<div class="floatLeft"><input type="radio" name="del[]" value="<?php echo($result['id']); ?>">Delete</div>
<div class="clearFloat"></div>

The radio buttons is where I am having issues. They work but not as needed as I am able to select both delete and approve for only one.

Looking to have it grouped by photo.  I am not sure how I should group each photo seperately.

  • Solution

Think of radio buttons as menu options. They need the same name (so the browser knows they are part of the same menu) but different values that the user selects.

Use the id (image id I presume) as part of the name to group them
 

<input type="radio" name="action[<?=$result['id']?>]" value="A"> Approve
<input type="radio" name="action[<?=$result['id']?>]" value="D"> Delete

Then to process the form data

foreach ($_POST['action'] as $id => $action) {

     if ($action == 'D') {
           // delete image whose ID is $id
     }
     elseif ($action == 'A') {
           // approve image whose ID is $id
     }
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.