Forum Moderators: coopster

Message Too Old, No Replies

Help with form submit buttons

Help with form submit buttons

         

ast0n

2:21 pm on Sep 1, 2007 (gmt 0)

10+ Year Member



Hi!

I'm a little stuck with a script I'm trying to make, to add a TV programme to a database.
There are quite a few fields on the input form, one of which is a 'cast' dropdown box. Next to this is an 'Add' button. The idea is you can select one cast member, click Add; the PHP then remembers that and displays it above the dropdown box. You can then select another and so on, eventually creating a big list above the dropdown. This all works fine.

However, I've also put a Delete button next to already added cast members, which allows you to remove anyone you've mistakenly added.

I'm using a submit button, <input name="deletecast" type="submit" value="ID" />, next to each already added cast member. When pressed, it will submit to the php script: deletecast=ID; ID being the ID of the cast member.

What I'm after, however, is for the button to say "Del" on it rather than the ID number of the cast member, but for it to still submit the ID number to the script.

I can't use an input type=hidden instead, because there will be a list of multiple cast members to be deleted, and all the hidden fields will be submitted, regardless of which delete button is pressed. I've tried using an input type=image, with a picture of an X and a value of ID; this works in Firefox but not in IE. I also want the form to submit all the other fields to the script, so that when the page re-loads it can be re-populated with the existing values already entered. Therefore I don't think I can use a local form tag for each submit button.

I've probably not explained this too well, so ask away if you don't know what I'm getting at. If anyone has any ideas I'd be extremely grateful! Thanks.

cameraman

6:59 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think a better way to do it would be to set up a radio button for each of the cast members and have a single delete button, but if you really prefer the multiple delete buttons, how about changing the name of the delete button to reflect the cast ID? I can't think of an elegant way to check for it. For example, if the name was a combination of "del" and the id number (say 36, so the button name would be del36) you'd do:
foreach($_POST as $name => $val)
if(substr($name,0,3) == 'del') {
$id = intval(substr($name,3));
// do delete stuff
break; // don't need to keep looking
} // this is a delete button