|
Posted by Robin on 12/22/05 12:12
swpulitzer@yahoo.com wrote:
> I have a page that lists a bunch of objects, stored in a database, to
> the user. After each object I'd like to do something like:
>
> object1 [edit] [delete]
> object2 [edit] [delete]
>
> and so on, where "edit" and "delete" are links. Right now, each link
> uses GET to pass the object ID to the scripit that will deal with it.
> For example, the urls for the first object links are something like:
>
> edit: http://www.host.com/edit.php?obj=object1
> delete: http://www.host.com/delete.php?obj=object1
>
> and similar for the second...you get the idea. This works alright for
> the edit option, since it's okay (even advantageous) for a user to
> bookmark it. However, it's problematic for the delete option. If a user
> bookmarks it, and then tries to visit the site later, they might
> unintentionally delete something. I can't use POST since this doesn't
> lend itself to a form. I know I could throw some javascript in there to
> handle it, but I'm trying to avoid javascript as much as possible.
>
> Does anyone know a better way to do this? Thanks.
>
You can use POST, so with a form:
<form name="myform" action="action.php" method="POST">
Have two hidden fields:
<input type="hidden" name="act" value="" />
<input type="hidden" name="obj" value="" />
The delete link can then be:
<a href="#" onclick="document.myform.act.value='delete';
document.myform.obj.value='object1'; document.myform.submit(); return
false">Delete</a>
Similarly, the edit link can be:
<a href="#" onclick="document.myform.act.value='edit';
document.myform.obj.value='object1'; document.myform.submit(); return
false">Edit</a>
You then only need one PHP page to handle edit and delete which just
checks $_POST['act'].
I'll actually suggest putting all this javascript in a function (e.g.
doact(act,obj) which returns false) so the link can just be:
<a href="#" onclick="return doact('delete','object1');">Delete</a>
HTH
Robin
Navigation:
[Reply to this message]
|