![]() |
|
#1
|
||||
|
||||
Multiple submit buttonsI have a file containing calendar information -- one entry per line. In cal.php I'm displaying the information in a table inside a form for maintenance. I want to also add a submit button to each row labeled delete. In the action file caldel.php I need to get the 'value' of the submit button clicked telling me which line of the file to delete.
I can't figure out how to set up the submit button and where to get the value from in caldel.php. Especially since I have no idea how many values will be on the cal.php page. In the input tag I obviously need value='delete'. Are hidden values available? Trying for something like: PHP Code:
Thanks... __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#2
|
||||
|
||||
|
Good question... one I have never asked myself, unfortunately. What I might suggest is creating another form for each row, including hidden values containing the id for the row to be deleted. Would that work? I don't know, since I am just guessing here...
So using your example code, let's say you try something like this instead: PHP Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
|
I think that you are on the right track WaltP. I don't believe there is any problem with having multiple submit buttons in a form, as long as they've all got unique name/value pairs to distinguish them.
However you might make things a lot easier on yourself by having: PHP Code:
So PHP Code:
That was unnecessary, but haven't typed PHP in a while |
|
#4
|
|||
|
|||
|
One thing to keep in mind with Garth's method, your buttons will be displayed with $n as the title of them. As long as you keep that in mind, you should have no problems.
If you wish to take a slightly different approach and use "delete" as the title of your submit button, try this: PHP Code:
PHP Code:
Another thing to think about is if you ever will want to delete multiple rows at once. If you do, change your form to look like this: PHP Code:
In this case, the processing code would be almost identical to that I have above, except instead of checking for the word "Delete", you'd check for a value of 1, like this: PHP Code:
Hope this helps. |
|
#5
|
||||
|
||||
|
Thanks for the help, guys. Unfortunately, nothing worked. The foreach gave me nothing but syntax errors -- No matter how I tried to format it. But it sounds like that's what I was looking for.
I wonder if my PHP is too old. I'll check it later. __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#6
|
||||
|
||||
|
This should be a simple problem to solve...
One way to debug these type of problems is to use print_r($_POST) to see what kind of data you're getting (you're using the POST method right?). Anyway, I've run into stuff like this lots of times.... The way you have your code now, as posted, since you're setting the name differently, .... might I suggest you do things differently to save yourself some hassle? A picture is worth a thousand words so let me show you a picture of your current code : PHP Code:
beautiful.... but hmm.... lets do this instead!! PHP Code:
Note, I created an HTML array variable called 'del'.. and $n is the key value... Next... how do you get the ID's selected? SIMPLE! PHP Code:
Note that 'del' $_POST variables will NOT be set, unless they are selected. That is why this code works. $id_array with a closed braket simply puts all $key values into each available slot of $id_array. Now, if you want to ensure they're going in, in order do this: PHP Code:
voila! I wrote an article on my webpage about problems like this... I just know this is going to work.. try it out. Anyway, when I first read this article I was half asleep... now I see what you're looking for. I hope this helps. Last edited by JdS : 12-Aug-2004 at 08:07.
Reason: Please insert your example PHP codes between [php] and [/php] tags
|
|
#7
|
||||
|
||||
|
Ahaaaa!! Fantastic!
I have no idea why I kept getting syntax errors... But now it seems to be peachy! Thanks JasonMichael, and all others who tried to help. I think I've got enough to finish the job now. __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| collecting user input from radio buttons. | Adelle29 | Web Design Forum | 1 | 31-May-2004 16:28 |
| strange sizeof(structure) - multiple of 8 | pinkpanther | C Programming Language | 11 | 30-May-2004 07:20 |
| GIDForums MemberRank buttons. | JdS | GIDForums™ | 2 | 24-Jan-2004 21:35 |
| GIDTopsites buttons | jrobbio | GIDTopsites™ | 0 | 26-Mar-2003 08:08 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The