Jump to content

multiple submit buttons - how to show usernames instead of userid numbers


jasonc

Recommended Posts

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

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.

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*).

 

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.

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.

Archived

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

×
×
  • 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.