Jump to content

[SOLVED] passing and processing unknown form names and values.


f1sh3r

Recommended Posts

Ok, i am working on a CMS for a branch of my college that works with continuing education, non traditional students, non-credit classes. In the user table for the DB, i have user access set up in this fashion:

 

user = 00000

student worker = 01000

instructor = 00200

program developer = 00030

super admin = 00004

 

so its combinable in that a program developer can also have instructor and student worker access = 01230 or that type of deal. super admins have a page where they can delegate access to different users. below is the code that is generated when they search for the "sh". i use the preg_match function to fill in the check boxes that pertain to each persons access level.

 

i know this is probably an easy solution, but im fried. what i need to know is how to successfully mold the changes for each user into a usable format. because i dont know what the u_id is going to be, i dont know how to handle the POST data.

 

What is the best way to set up the form so that the variables/values can be tied to the user? im having a hard time explaining, sorry.

 

i would like to be able to do $id_access = "0".$student.$instructor.$developer.$super;  <-not those exact variables, but i need to be able to split up the values from multiple users using a form like the one below. if someone can help me with better names/values for my form or some type of array/foreach/while magic, i would be extremely excited.

 

hopefully someone understands my problem and took the time to read it. thanks.

 

 

<h2>Found Users</h2>
<form name="updateadmin" method="post" action="admin.php?action=sup_delegate"> 

  <h3>Jill Welsh</h3>
  <div class="m10">
  <input type="hidden" name="u84" value="84" /> 
<input type="checkbox" name="s84" id="s84" value="1"  /> <label for="s84">Student Worker</label> 
<input type="checkbox" name="i84" id="i84" value="2" checked="checked" /> <label for="i84">Instructor</label> 
<input type="checkbox" name="d84" id="d84" value="3"  /> <label for="d84">Program Developer</label> 
<input type="checkbox" name="a84" id="a84" value="4"  /> <label for="a84">Super Admin</label> 
</div>

  <h3>Julie Sharrow</h3>
  <div class="m10">
  <input type="hidden" name="u72" value="72" /> 
<input type="checkbox" name="s72" id="s72" value="1" checked="checked" /> <label for="s72">Student Worker</label> 
<input type="checkbox" name="i72" id="i72" value="2" checked="checked" /> <label for="i72">Instructor</label> 
<input type="checkbox" name="d72" id="d72" value="3" checked="checked" /> <label for="d72">Program Developer</label> 
<input type="checkbox" name="a72" id="a72" value="4"  /> <label for="a72">Super Admin</label> 
</div>

  <h3>Michael Sheppard</h3>
  <div class="m10">
  <input type="hidden" name="u26" value="26" /> 
<input type="checkbox" name="s26" id="s26" value="1"  /> <label for="s26">Student Worker</label> 
<input type="checkbox" name="i26" id="i26" value="2" checked="checked" /> <label for="i26">Instructor</label> 
<input type="checkbox" name="d26" id="d26" value="3"  /> <label for="d26">Program Developer</label> 
<input type="checkbox" name="a26" id="a26" value="4"  /> <label for="a26">Super Admin</label> 
</div>

  <h3>Ryan Fisher</h3>
  <div class="m10">
  <input type="hidden" name="u35" value="35" /> 
<input type="checkbox" name="s35" id="s35" value="1" checked="checked" /> <label for="s35">Student Worker</label> 
<input type="checkbox" name="i35" id="i35" value="2" checked="checked" /> <label for="i35">Instructor</label> 
<input type="checkbox" name="d35" id="d35" value="3" checked="checked" /> <label for="d35">Program Developer</label> 
<input type="checkbox" name="a35" id="a35" value="4" checked="checked" /> <label for="a35">Super Admin</label> 
</div>

  <h3>Teri Sheely</h3>
  <div class="m10">
  <input type="hidden" name="u87" value="87" /> 
<input type="checkbox" name="s87" id="s87" value="1"  /> <label for="s87">Student Worker</label> 
<input type="checkbox" name="i87" id="i87" value="2" checked="checked" /> <label for="i87">Instructor</label> 
<input type="checkbox" name="d87" id="d87" value="3"  /> <label for="d87">Program Developer</label> 
<input type="checkbox" name="a87" id="a87" value="4"  /> <label for="a87">Super Admin</label> 
</div>

<div class="right">
<input type="hidden" name="qupeop" value="sh" />
<input type="submit" name="sup_admin_update" value="Change">
</form>

Link to comment
Share on other sites

i would like to be able to do $id_access = "0".$student.$instructor.$developer.$super;  <-not those exact variables, but i need to be able to split up the values from multiple users using a form like the one below. if someone can help me with better names/values for my form or some type of array/foreach/while magic, i would be extremely excited.

so you're trying to use those variable values to build those 5 digit numbers?

 

 

$access[1] = 01000; //student worker

$access[2] = 00200; //instructor

$access[3] = 00200; //program developer

$access[4] = 00200; //super admin

 

 

for ($i=0; $i<$users; $i++) //for every user

{

    $userid = $_REQUEST['you.$i']; //or get the value, 1,2,3,4 for student worker, instructor, program developer or super admin. I said you.$i because it'd go through u1, u2, u3, u4 etc etc. do as it fits.

    $id_access = $access[$userid];

}

 

hows that?

Link to comment
Share on other sites

i think i have come up with a solid coding scheme. can someone tell me if this is error prone or bad coding in general? thanks.

 

<html>
<body>

<?php


if (isset($_POST[sup_admin_update])) {
  foreach ($_POST as $user => $value) {
    if (is_array($value)) {
      $admin = implode($value);
      echo "$user is $admin <br />"; // 84 is 00200, 72 is 01230
      // mysql_query ("UPDATE users SET u_access = $admin WHERE u_id = $user") or die();
    }
    else {
      $$user = $value;
      echo "$user is $value <br />"; // qupeop is sh, sup_admin_update is Change
    }
  }
}

?>

<form action="index.php" method="post">

  <h3>Jill Welsh</h3>
  <div class="m10">
  
  <!-- hidden variables if they dont check it, it will still pass a 0 -->
<input type="hidden" name="84[0]" value="0" />
<input type="hidden" name="84[1]" value="0" />
<input type="hidden" name="84[2]" value="0" />
<input type="hidden" name="84[3]" value="0" />
<input type="hidden" name="84[4]" value="0" />

<input type="checkbox" name="84[1]" id="s84" value="1"  /> <label for="s84">Student Worker</label>
<input type="checkbox" name="84[2]" id="i84" value="2" checked="checked" /> <label for="i84">Instructor</label>
<input type="checkbox" name="84[3]" id="d84" value="3"  /> <label for="d84">Program Developer</label>
<input type="checkbox" name="84[4]" id="a84" value="4"  /> <label for="a84">Super Admin</label>
</div>

  <h3>Julie Sharrow</h3>
  <div class="m10">
  
  <!-- hidden variables if they dont check it, it will still pass a 0 -->
<input type="hidden" name="72[0]" value="0" />
<input type="hidden" name="72[1]" value="0" />
<input type="hidden" name="72[2]" value="0" />
<input type="hidden" name="72[3]" value="0" />
<input type="hidden" name="72[4]" value="0" />

<input type="checkbox" name="72[1]" id="s72" value="1" checked="checked" /> <label for="s72">Student Worker</label>
<input type="checkbox" name="72[2]" id="i72" value="2" checked="checked" /> <label for="i72">Instructor</label>
<input type="checkbox" name="72[3]" id="d72" value="3" checked="checked" /> <label for="d72">Program Developer</label>
<input type="checkbox" name="72[4]" id="a72" value="4"  /> <label for="a72">Super Admin</label>
</div>

<div class="right">
<input type="hidden" name="qupeop" value="sh" />
<input type="submit" name="sup_admin_update" value="Change">
</form>

</body>
</html>

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.