Jump to content

form button problem


ltbaggz

Recommended Posts

I am using a loop to display form buttons to remove certain items from a database.  I have tried a couple of different styles and although it will work in firefox it will not work in internet explorer.  I am displaying a delete record button with a value of a distinct entry in the database.

here is a snippet from my code
[code]<form method="post" action="do_it.php">
<li id="list_item">
<button name="delete" value="72" type="submit">Delete</button>
</li>

<li id="list_item">
<button name="delete" value="77" type="submit">Delete</button>
</li>

</form>[/code]

this is what my php script generates, ie will not recognize the submit.  if i use input tags then i am also having a input hidden value with the database record to be deleted as well as the button and when i access it in the $_POST variable it does not contain the correct value of the record to be deleted.  I am not sure how to make this name value unique and then be able to access it in the $_POST when i run my query.  hopefully i explained in a way that can be understood.

Thanks
Drew
Link to comment
Share on other sites

if i use a input button then i need a hidden value as well to be able to pass the id to delete.  when my php generates this form it can have any number of entries, the name="delete" is the same for all of the different buttons to choose from and when it is submitted, the $_POST variable does not contain the proper id to delete. this is because im declaring multiple inputs with the same name.  I could change the script to append an index onto the name but then how do i determine what button is pressed, when i check for it in my script?  hope this makes sense.
Link to comment
Share on other sites

How about something like this:

<input type="image" src="/images/delete.gif" name="Delete" value="77"><br>
<input type="image" src="/images/delete.gif" name="Delete" value="78"><br>
<input type="image" src="/images/delete.gif" name="Delete" value="79"><br>
.
.
.

You would need to create a delete button image, but it would work.
Link to comment
Share on other sites

[quote author=sloshire1 link=topic=121464.msg500129#msg500129 date=1168297762]
How about something like this:

<input type="image" src="/images/delete.gif" name="Delete" value="77"><br>
<input type="image" src="/images/delete.gif" name="Delete" value="78"><br>
<input type="image" src="/images/delete.gif" name="Delete" value="79"><br>
.
.
.

You would need to create a delete button image, but it would work.
[/quote]

No same name for all buttons will create problems instead give names  as Delete1, Delete2, ....
Link to comment
Share on other sites

if i use input type=button value=uid i have unique entries but then how do i access it when the button is clicked? 
what should the php read (i know im in the html forum) but i have something like this
[code]
if(isset($_POST[uid_1]))
{
do something
}
[/code]

so here i check uid_1 now what if uid_2 is clicked?  is there a way i can have php account for this and see what is set and access its value?
Link to comment
Share on other sites

can I make a suggestion....

don't use a button for each record - use a check box aginst each record and ONE submit button at the bottom of the form...

<input type="checkbox" name="delete[]" value="77" />
<input type="checkbox" name="delete[]" value="78" />
<input type="checkbox" name="delete[]" value="79" />

this makes your code in the next page even easier.

sice these are checkboxes they only get a value if they are actually checked - otherwise html pretendsw they never existed.

In the processing script you can now delete multiple records all with one query like so.

[code]<?php

$ids = implode(',', $_POST['delete']);

// this will make a comma separated string of all the delete checkbox values.

$qry = "DELETE FROM `a_table` WHERE `id` IN (" . $ids . ")";
$qry = mysql_query($qry);

?>
[/code]
Link to comment
Share on other sites

Thanks for the input, i was trying to stay away from using checkboxes, i felt buttons fit in the application better.  But i may have to resort to it.  Thanks for the input i like that little trick with the query.  I might just do a link to a page that describes the entry to be deleted, and the user can either edit it or delete it.  Have to figure something else out.

Thanks
Drew
Link to comment
Share on other sites

Ah I understand. You are wanting to take them to a page that shows what they are about to delete and then confirm.

In that case the correct mark-up would simply be a link - not a button. simply place some vars in the url.

<a href="/path/to/file/delete.php?record=77" title="Delete Record 77">Delete</a>
<a href="/path/to/file/delete.php?record=78" title="Delete Record 78">Delete</a>
<a href="/path/to/file/delete.php?record=79" title="Delete Record 79">Delete</a>

Then delete.php can show the stuff and have a confirmation button at the bottom which when pressed will do the delete.
Link to comment
Share on other sites

yeaup that is the route i am taking, originally i wanted to have the delete button right on the page, but thats not going to work out, so im gonna have to do it that way.  oh well, it will eventually work one way or another.

thanks for the help
drew
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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