Jump to content

how to convert radio button to checkbox - code included


nandwana_vikas

Recommended Posts

Hi,

 

I have this site where user submits their questions and based on the quality I select or reject them. IF the user's submitted qn is selected he get +1 points for 1 questions otherwise none.

But in my admin panel when I get a questions, due to the radio button I can select/reject only one question at a time. It takes me a lot of time since everyday people submit a lot of question. So I want to change the "radio option" to "checkbox option" in the code so that I can select/reject multiple question at once. I have pasted the code. Any help would be really appreciated. IF I am at the wrong forums, could you please suggest me the right place. thanks a lot.

 

<?php
session_start();
include_once("../includes/config.inc.php");
include_once("../classes/database.class.php");
include_once("../classes/main.class.php");
include_once("../includes/functions.inc.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
print_r($_POST);
//if( isset($_REQUEST['hdnAcceptSubmit']) ){			

if( isset($_SESSION['user']['email'] ) ){

$counter=0;
?>
<div class="formHeading">List of Questions need to Accept / Reject</div><br/><br/>
<!--<form id="frmAccept" onsubmit="postHTML('mainContent','accept.php', 'frmAccept' )" >-->
<form id="frmAccept"  method="post" action="process.php" name="frmAccept">  
<div id="topScores">
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width:10px;">#</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 55px;">Name</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 55px;">Question</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 75px;">Answer </div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 95px;">Option 1</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 65px;">Option 2</div>
<div class="header row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 65px;">Option 3</div>
<br style="clear:both;"/>
<?

$db->connect(); 

$counter = 1;
$totalpoints = new User();

$sql = "SELECT U.first_name,Q.question,Q.answer,Q.opt_1,Q.opt_2,Q.opt_3,Q.enabled,Q.question_id,Q.user_id FROM ".$db->pre."quiz_questions Q,".$db->pre."quiz_users U WHERE Q.enabled = 0 and Q.user_id = U.user_id";

$results = $db->query($sql);
while ($user = $db->fetch_array($results) ) {
?>
        
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD481"?>; line-height: 18px; float:left; width: 10px; padding-top:5px;">
<input type="radio" name="group1" value="<?=$user['question_id']?>" align="absmiddle" /></div>  
<input type="hidden" name="<?=$user['question_id']?>" id="<?=$user['question_id']?>" value="<?=$user['user_id']?>" /> 
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 55px;"><?=$user['first_name']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 55px;"><?=$user['question']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 75px;"><?=$user['answer']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 95px;"><?=$user['opt_1']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 65px;"><?=$user['opt_2']?></div>
<div class="row" style="background-color: <?=($counter%2 == 0)?"#CBD48F": "#CBD4FF"?>; line-height: 18px; float:left; width: 65px;"><?=$user['opt_3']?></div>
<br style="clear:both;"/>		
<?	
$counter++;	
}
//$db->close(); 
?>
  <input type="submit" class="button" style="margin-left: 65px; margin-top: 15px;" value="Accept" id="btnaccept" name="btnaccept" /> 
<input type="submit" class="button" style="margin-left: 65px; margin-top: 15px;" value="Reject" id="btnreject" name="btnreject"/>

<!--      <input type="hidden" id="hdnAcceptSubmit" name="hdnAcceptSubmit" value="true"/> -->

</div>
</form>
<? } else {?>
<div class="header">Please login to View the Submitted Questions<br/></div>	
<?	    
}
?>

</body>
</html>

 

Mod edit : please use

..

tags.

 

Link to comment
Share on other sites

Hmm, I'm a little pressed for time to be reading through all of that to make sense of it. But, basically you just need to use checkboxes instead of a radio group. Give each checkbox the same name in the format name="something[]" with the brackets so the results will be received as an array.

 

Only "checked" values will be returned. I would suggest two columns of checkboxes (one for approval and one for rejection). you could use one checkbox for each, but then you have to use a flag or some other means to track which records you were just reviewing (in case another record was added while you were reviewing). It also allows you to NOT review some of the questions and save for later.

 

So, if you have two sets of checkboxes with the names rejected[] and approved[] you could just run two queries. Something like:

 

//Set approved to false for rejected records
$query = "UPDATE table SET approved=0 WHERE id IN (" . implode(',', $_POST['rejected'] . ")";
//Set approved to true for approved records
$query = "UPDATE table SET approved=1 WHERE id IN (" . implode(',', $_POST['approved'] . ")";

Link to comment
Share on other sites

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.