I laid out a form that allowed a user to approve / deny a registrant to a site. It was originally set up as a link (showing 'approve' if the user was not already approved, and deny if the user was already approved); when the admin chose 'approve' or 'deny', it would then direct them to a case in a switch statement, with each bit of user info contained in its own form, and based on the case perform an appropriate update to the database, and redisplay the newly updated data.
A request has been made to change the 'approve'/'deny' links to dropdowns. I was considering allowing a similar functionality with the dropdown (much like the javascript 'onchange'), but it seems to be difficult to pull this off the way I have my form structured. I was looking to allow this same switch redirection based on the user's selection for each dropdown.
Is there a way to do what I want, or should I reconsider my form?
Relevant code follows.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="approvalForm">
<table border="0">
#<...SNIP...>
<td>
<select id="approvalStatus" name="approvalStatus" tabindex="5">
<?php
$query2 = "SHOW COLUMNS FROM registration LIKE 'approvalStatus'";
$result2=mysql_query($query2);
if(mysql_num_rows($result2) > 0){
$row2=mysql_fetch_row($result2);
$options=explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row2[1]));
sort($options);
$count = count($options);
for ($x = 0; $x < $count; $x++ ){
$option = $options[$x];
if ($option == "F") {
$approve = "Not Approved";
} elseif ($option == "T") {
$approve = "Approved";
}
?>
<option id="approvalStatus" value="<?php echo $options[$x]; ?>" <?php if ($option == $row['approvalStatus']){ echo "selected"; } ?>><?php echo $approve; ?></option>
<?php
}
}
?>
</select>
<td width="50" align="right"><a href="<?php echo $_SERVER['PHP_SELF'] . "?opt=edit&email=" . urlencode($row['email']); ?>">Edit</a></td>
<td width="50" align="right"><a href="<?php echo $_SERVER['PHP_SELF'] . "?opt=delete&email=" . urlencode($row['email']); ?>">Delete</a></td>
#<...SNIP...>
switch ($_GET['opt']){
case "approve":
$query="UPDATE registration SET approvalStatus='T' WHERE email='".$_GET['email']."'
AND approvalStatus = 'F'
";
mysql_query($query) or die(mysql_error());
echo "Record Updated.<br /><br />";
formdisplay();
mysql_close();
break;