jasonc Posted August 11, 2010 Share Posted August 11, 2010 not sure how i do this but i have a list of userid and username that i wish to have shown in a form when the admin can edit their details. they click their name to be taken to a new page that shows the edit page. the edit page it ready it is the first part that allows admin to select the user that i have a problem with. the following shows the userid of the user and not the username. what method can i use to have with edit user or their names show in the buttons this is what i am using but it shows the userid can this be done? <input type="submit" name="userid" value="my name here"> EDIT: but i will need to obviously know what button was clicked and get the userid of the user Link to comment https://forums.phpfreaks.com/topic/210423-multiple-submit-buttons-how-to-show-usernames-instead-of-userid-numbers/ Share on other sites More sharing options...
ignace Posted August 11, 2010 Share Posted August 11, 2010 Meet the <button>: <button type="submit" name="userid" value="<?php print $userid ?>"><?php print $username ?></button> Link to comment https://forums.phpfreaks.com/topic/210423-multiple-submit-buttons-how-to-show-usernames-instead-of-userid-numbers/#findComment-1097997 Share on other sites More sharing options...
XeNoMoRpH1030 Posted August 11, 2010 Share Posted August 11, 2010 Be careful with <button> though. It's known that IE does not use it in the same manner as other browsers. Why are you trying to use a button anyway? Just curious as it doesn't seem like a case where you'd want to use one. Link to comment https://forums.phpfreaks.com/topic/210423-multiple-submit-buttons-how-to-show-usernames-instead-of-userid-numbers/#findComment-1098141 Share on other sites More sharing options...
linus72982 Posted August 11, 2010 Share Posted August 11, 2010 You don't have to use buttons. You can have multiple submits in a form and differentiate which was clicked. Try something like: <?php for ($i=1, $i<=$numberOfUsers, $i++){ echo '<input type="submit" name="submitter" value="'.$userid.'->'.$username.'" />} ?> and then have something like this in the processing script: $temp = stripos($_POST['submitter'], '->'); $userID = substr($_POST['submitter'], 0, $temp); $temp = $temp + 2; $userName = substr($_POST['submitter'], $temp); At least that's how I'd do it, now you have the userID and the userName in the processing script of the button they pressed. I didn't test the code, there might be little errors, but it should work overall (*should*). Link to comment https://forums.phpfreaks.com/topic/210423-multiple-submit-buttons-how-to-show-usernames-instead-of-userid-numbers/#findComment-1098262 Share on other sites More sharing options...
linus72982 Posted August 11, 2010 Share Posted August 11, 2010 I see one error I wrote, the first piece of code should actually be: echo '<input type="submit" name="submitter" value="'.$userid.'->'.$username.'" />';} ?> Notice I added '; to the very end of the line. Small error, but there nonetheless. Link to comment https://forums.phpfreaks.com/topic/210423-multiple-submit-buttons-how-to-show-usernames-instead-of-userid-numbers/#findComment-1098314 Share on other sites More sharing options...
ignace Posted August 13, 2010 Share Posted August 13, 2010 Other options available: <input type="submit" name="99" value="MyUsername" onclick="this.value = this.name; this.name = 'userid';"> ----- <input type="hidden" name="userid" value="99"> <input type="submit" value="MyUsername"> Both are handled like: $userid = $_POST['userid']; The latter is better if you want to support graceful degradation. Link to comment https://forums.phpfreaks.com/topic/210423-multiple-submit-buttons-how-to-show-usernames-instead-of-userid-numbers/#findComment-1098950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.