Jump to content


Photo

dynamic form and checkbox question *solved*


  • Please log in to reply
13 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 31 July 2006 - 07:55 PM

he guys,

I have a dynamic form that displays users and their level of validation. I was wondering how would I add a checkbox to confirm the level of validation (which is in a drop down) so that I can select as many users as I want and when I click on validate, it validates their level? The checkbox needs to contain the username and the level that was chosen in the dropdown (I think)

here's what I have so far

<form action="admin.php?a=viewusers&action=validate" method="post" name="validate" id="validate">
	<input type="hidden" name="process_b" value="yes">
	<div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>
	<?php if (!isset($_SESSION['custom_browse']) && !isset($_GET['action'])) {
	$browse = mysql_query("SELECT * FROM mtlguest_users WHERE level='2' ORDER BY id DESC") or die(query_error());
	}
	if (isset($_SESSION['custom_browse']) && !isset($_GET['action'])) {
	$browse = $_SESSION['custom_browse'];
	}
	if (!isset($_SESSION['custom_browse']) && isset($_GET['action'])) {
	$browse = $_SESSION['all_validate'];
	}
	while ( $row = mysql_fetch_array($browse)) {
	echo '
	<div style="margin-left:9px; margin-top:7px; width:354px ">
	  <div>Username: <strong>'.$row['username'].'</strong></div>
	  <div>Last Name: <strong>'.ucfirst($row['lname']).'</strong></div>
	  <div>First Name: <strong>'.ucfirst($row['fname']).'</strong></div>
	  <div>Age: <strong>'.age($row['date_birth']).'</strong></div>
	  <div>Sexe: <strong>'.ucfirst($row['gender']).'</strong></div>
	  <div>Location: <strong>'.$row['city'].'</strong></div>
	  <div>Active: <strong>'.$row['active'].'</strong></div>';
	  if ($browse != $_SESSION['all_validate']) {
	  echo '<div>Level of validation: <strong>'.$row['validation'].'</strong></div>';
	  } else {
	  	echo '<div>Level of validation: <select name="valid_lvl" id="valid_lvl" style="width:40px; height:12px; font-family:tahoma; font-size:10px; color:#9A400C ">
  <option>Choose one</option>';
      foreach ($aValid as $val) {
   	  echo "<option value='$val'";
      if ($val==$row['validation']) { echo " selected"; }
      echo ">".$val;
      }
echo '</select> Validate: <input type="checkbox" name="validation[]" value=""> </div>';
	  }
	  
	echo '<div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div>
	</div>
	
	<div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';
	}
	?>
	</form>

I hope I was clear enough

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 31 July 2006 - 11:38 PM

You can do

input type='checkbox' name='validate[]' value='IDNUMBER'>
Using [] makes the result in an array
and changing IDNUMBER
with the unique number from the database
Then you can run a query

$validate = $_POST["validate"];
$num_array = count($validate);

for($i = 0; $i < $num_array; $i++){
$query = "UPDATE QUERY WHERE IDNUMBER = ".$validate[$i]."
}

Remember arrays start at 0
counting starts at 1
so if the array had 5 results, the count would be 5, the result would be
0
1
2
3
4


Tell me the problem, I will try tell you the solution

#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 07:12 PM

thanks onlyican but how do I grab the value of the drop down at the same time, so if for one entry I choose level 3 in the drop down and check the validate checkbox, how do I associate that level to that id?

#4 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 08:37 PM

would using a 2d array work??

something like grabbing the id of what has been checked and the level at the same? not sure how to do it though

#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 01 August 2006 - 08:54 PM

something like validate[$level][]??
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#6 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 09:01 PM

where $level would be the value of the drop down?

I'm really not sure how to accomplish this, the values that have to be stored in the array would be the id of the user and the chosen level but those values are only stored if I checked "validate"

so if I have 5 entries and I only select 3 of them the array would like

Array
(
   [2] => 0
   [4] => 3
   [5] => 5
)

where the first part is the id number and the second part is the level.

#7 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 01 August 2006 - 09:17 PM

you can do something like <input type='checkbox' name='validate[$level]' value='$value'>

do you have the users' level information when you construct the checkbox?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#8 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 09:47 PM

well their default level is 0 but I want to be able to change that with a drop down but I want to be able to keep some users at level 0 so if the level is 0 in the drop down and I check validate it will "confirm" his level.

Trying to make this as clear as possible...

If I have a list of 100 users, I want to validate them by choosing the level and checking the checkbox next to the drop down, so if I select level 3 in the drop down and check the box it will update his level and add "true" to validated.

so far this is what I have to process the form

$validate = $_POST['validate'];
$num_array = count($validate);
for ($i=0; $i < $num_array; $i++) {
$query = "UPDATE " . $prefix . "users SET validation='$validation',validated='true' WHERE id = ".$validate[$i]."";
$result = mysql_query($query) or die(query_error());
}

what I'm missing is the $validation (which is the level)


#9 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 01 August 2006 - 10:08 PM

so the layout is this?
USER DROPDOWN CHECKBOX
USER DROPDOWN CHECKBOX

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#10 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 10:13 PM

well here I'll show you the form

<form action="admin.php?a=viewusers&action=validate" method="post" name="validate" id="validate">
<input type="hidden" name="process_b" value="yes">
<div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>
<?php if (!isset($_SESSION['custom_browse']) && !isset($_GET['action'])) {
$browse = mysql_query("SELECT * FROM users WHERE level='2' ORDER BY id DESC") or die(query_error());
}
if (isset($_SESSION['custom_browse']) && !isset($_GET['action'])) {
$browse = $_SESSION['custom_browse'];
}
if (!isset($_SESSION['custom_browse']) && isset($_GET['action'])) {
$browse = $_SESSION['all_validate'];
}
while ( $row = mysql_fetch_array($browse)) {
echo '
<div style="margin-left:9px; margin-top:7px; width:354px ">
<div>Username: <strong>'.$row['username'].'</strong></div>
<div>Last Name: <strong>'.ucfirst($row['lname']).'</strong></div>
<div>First Name: <strong>'.ucfirst($row['fname']).'</strong></div>
<div>Age: <strong>'.age($row['date_birth']).'</strong></div>
<div>Sexe: <strong>'.ucfirst($row['gender']).'</strong></div>
<div>Location: <strong>'.$row['city'].'</strong></div>
<div>Active: <strong>'.$row['active'].'</strong></div>';
if ($browse != $_SESSION['all_validate']) {
echo '<div>Level of validation: <strong>'.$row['validation'].'</strong></div>
<div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div>
</div>
	
<div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';
} else {
echo '<div>Level of validation: <select name="valid_lvl" id="valid_lvl" style="width:40px; height:12px; font-family:tahoma; font-size:10px; color:#9A400C ">
<option>Choose one</option>';
foreach ($aValid as $val) {
echo "<option value='$val'";
if ($val==$row['validation']) { echo " selected"; }
echo ">".$val;
}
echo '</select> Validate: <input type="checkbox" name="validate[]" value="'.$row['id'].'"></div>
<div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div>
</div>
	
<div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';
	  
}
}
echo '<div style="margin-top:10px"><input type="submit" name="Submit" value="Validate"></div>';
?>
</form>

the reason I want a checkbox is because I don't want to validate everyone in 1 shot

sorry about the formating but whenever I copy and paste from dreamweaver everything is weird

#11 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 01 August 2006 - 10:15 PM

ok you can use
<select name="valid_lvl[$row[id]]">

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#12 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 10:35 PM

and how do I process it?

#13 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 01 August 2006 - 10:42 PM

<?php
$validate = $_POST['validate'];
$num_array = count($validate);
for ($i=0; $i < $num_array; $i++) {
  $id = $validate[$i];
  $query = "UPDATE " . $prefix . "users SET validation='" .$valid_lvl[$id]. "',validated='true' WHERE id = ".$id."";
  $result = mysql_query($query) or die(query_error());
}
?>

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#14 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 01 August 2006 - 10:51 PM

perfect! thank you so much




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users