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
https://forums.phpfreaks.com/topic/33296-form-button-problem/
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156125
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156167
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156771
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156945
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156979
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156981
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
https://forums.phpfreaks.com/topic/33296-form-button-problem/#findComment-156985
Share on other sites

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.