Jump to content

dynamic form and checkbox question *solved*


digitalgod

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
Link to comment
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

Link to comment
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.
Link to comment
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)
Link to comment
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
Link to comment
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]
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.