Jump to content

Archived

This topic is now archived and is closed to further replies.

digitalgod

dynamic form and checkbox question *solved*

Recommended Posts

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

[code]
<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>
[/code]

I hope I was clear enough

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

[code=php:0]
$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());
}
[/code]

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

Share this post


Link to post
Share on other sites
so the layout is this?
[code]USER DROPDOWN CHECKBOX
USER DROPDOWN CHECKBOX
[/code]

Share this post


Link to post
Share on other sites
well here I'll show you the form

[code]
<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>
[/code]

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

Share this post


Link to post
Share on other sites
[code]<?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());
}
?>[/code]

Share this post


Link to post
Share on other sites

×

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.