Jump to content

Pulling Radio Buttons, Select Box and Submit Button Together


Diegar

Recommended Posts

Hello,I am trying to create an admin page with a form for editing, warning, or deleting members, all in one. I apologize in advance for dumping a large spot of code:

<form name="users" action="userActions.php" method="POST">  <table width="250" border="0" cellspacing="0" cellpadding="3">	<tr bgcolor="#000033"> 	  <td height="30" colspan="3"> 		<div align="center"><font face="Arial, Helvetica, sans-serif" size="4"><b><font color="#FFFFFF">Edit/Delete 		  Members</font></b></font></div>	  </td>	</tr>	<tr> 	  <td width="37" bgcolor="F1F1F1" align="center"> <font face="Arial, Helvetica, sans-serif"> 		<input type="radio" name="username" value="edit" id="edit">		</font></td>	  <td width="38" bgcolor="F1F1F1" align="left"><font face="Arial, Helvetica, sans-serif">Edit</font></td>	  <td height="200" width="175" align="center" valign="middle" bgcolor="F1F1F1" rowspan="4"> 		<style type="text/css">		select {font-family: Arial, Helvetica, sans-serif, monospace;}		</style>		<font face="Arial, Helvetica, sans-serif">Select Member</font><tt> 		<select name="members" style="width:150px;margin:5px 0 5px 0;" multiple size="10">		  <?$memQuery = "SELECT user FROM users ORDER BY user"; //Get all the user name rows$getUsers = mysql_query($memQuery,$msa) or DIE (mysql_error);$userRow = mysql_num_rows($getUsers);$ur = 0;while (($ur < $userRow))	{	$username=mysql_result($getUsers , $ur , "user");		echo "<option>$username";	$ur++;	}	?>		</select>		</tt> </td>	</tr>	<tr> 	  <td width="37" bgcolor="F1F1F1" align="center"> <font face="Arial, Helvetica, sans-serif"> 		<input type="radio" name="username" value="warn" id="warn">		</font></td>	  <td width="38" bgcolor="F1F1F1" align="left"><font face="Arial, Helvetica, sans-serif">Warn</font></td>	</tr>	<tr> 	  <td width="37" bgcolor="F1F1F1" align="center"> <font face="Arial, Helvetica, sans-serif"> 		<input type="radio" name="username" value="delete" id="delete">		</font></td>	  <td width="38" bgcolor="F1F1F1" align="left"><font face="Arial, Helvetica, sans-serif">Delete</font></td>	</tr>	<tr> 	  <td width="75" bgcolor="F1F1F1" align="center" colspan="2"><font face="Arial, Helvetica, sans-serif"><input type="SUBMIT" name="users" value="Go"></font></td>	</tr>  </table></form>

I am trying to get the output to the next page. But i am rather lost in how to get it. The idea is, they select the username, put a radio selection next to the appropriate action, and then hit the submit button. The question is, how, on the userActions.php page, do i grab the correct data? I feel like i am going in circles, but i have never messed with radio buttons before. Any help, or direction, would be great!

Link to comment
Share on other sites

Nevermind, i figured it out..

$def = $_POST['username'];$username = $_POST['members'];if ($def == 'edit') echo "Edit Member, $username";if ($def == "warn") echo "Warn Member, $username";if ($def == "delete") echo "Delete Member, $username";

It worked right, so far

Link to comment
Share on other sites

This is what switch statements are used for also. If you have a series of if statements where you are checking the value of the same expression, you can just use a switch statement instead. For only 2 or 3 if statements a switch wouldn't make a big deal, but it will be more efficient for larger possibilities.

switch($def){  case 'edit':	echo "Edit member";  break;  case 'warn':	echo "Warn member";  break;  case 'delete':	echo "Delete member";  break;  default:	echo "Unknown action: {$def}";  break;}

The default case is optional. Cases also have a property called fall-through. If a case does not have a break statement, then the execution will fall through to the next case, until it finds a break. So this switch statement would print out "test" however many times the $i variable says. So if $i is 5, it prints "test" 5 times. Since there are no breaks, the execution will start at the first point it can (the first case statement to be true) and will keep going until it hits a break.

switch($i){  case 10:	echo "test";  case 9:	echo "test";  case 8:	echo "test";  case 7:	echo "test";  case 6:	echo "test";  case 5:	echo "test";  case 4:	echo "test";  case 3:	echo "test";  case 2:	echo "test";  case 1:	echo "test";	break;  default:	echo $i;	break;}

You can take advantage of fall-through if you have a set of things that need to happen for more cases then one. You can put the specialized things in their own cases and fall-through to the general purpose things.

switch($action){  case 'changesize':	$width = 100;	$height = 100;  case 'reposition':	$left = 100;	$top = 50;  default:	//always do this	$text = "updated";	break;}

That way if $action were "reposition", it would set the position variables and then update the text. If $action were "changesize" then it would change the dimensions, then repositon, then update the text. If action were anything else then it would only update the text.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...