Page 1 of 1

passed variables from form, using multiple image sumbit IE

Posted: Sun Feb 11, 2007 8:37 am
by sargus
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello to all,

sorry for long post please be patient  I can't get over one little problem, i do have some output list of items from database and i want to add two image submiting form  for each item, let's say for edit or delete. It should pass actual item id and action what to do (edit or delete ).

For accessibilty and security reasons , this must be accomplished without css or JavaScript. I can't neither use the GET method, it must be passed by POST. It must be accesible with/without enabled css and pictures.

I would like to avoid doing special form for every item like that. 
[syntax="html"]
item id 1
<form action=".." method="post">
        <input type="hidden" name="id" value="1">
        <input type="hidden" name="action" value="edit">
</form>
<form action=".." method="post">
        <input type="hidden" name="id" value="1">
        <input type="hidden" name="delete" value="edit">
</form>
item id 2
      and so on .......
Unfortunately it's very difficult because of strange IE behavior.

First of I tried to add input type image for both buttons passing different values:

Code: Select all

<form action=".." method="post">
    item id 1 
        <input type="image" name="edit" value="1" alt="edit " src=".."> 
        <input type="image" name="delete" value="1" alt="delete" src="..">

    item id 2 
       <input type="image" name="edit" value="2" alt="edit " src="..">
      <input type="image" name="delete" value="2" alt="delete" src="..">
</form>
[/syntax]

Code: Select all

if (isset($_POST["edit"]){
   $action="edit";
   $id=$_POST["edit"];
} elseif (isset($_POST["delete"]){
   $action="delete";
   $id=$_POST["delete"];
}
mozilla works fine passing following:

edit_x => ""
edit_y => ""
edit => "1"

The problem is that IE will not pass name and value, but just position adding .xy (_xy in php) where you clicked the image button:

edit_x => "10"
edit_y => "10"




After some time i give up and tried another solotion with button element using following code:

Code: Select all

<form action=".." method="post">
   item id 1
         <button type="submit" value="1" name="edit"><img src=".." alt="edit" /></button>
         <button type="submit" value="1" name="delete"><img src=".." alt="delete" /></button>

   item id 2
        <button type="submit" value="2" name="edit"><img src=".." alt="edit" /></button>
        <button type="submit" value="2" name="delete"><img src=".." alt="delete" /></button>
</form>
Guess what, all is fine in mozzila passing following:

edit => "1"

but variables from passed by IE are wrong, it pass the "innerHTML" between <button></button>tag, and what more it passed both buttons:

edit => "<img src=".." alt="edit" />"
delete => "<img src=".." alt="delete" />"


I don't want to discuss if IE is working good or right etc., i readed many topics on that, i would like to discuss if there is a solution for this problem. Doees anybody have idea how to get over this ?

Thanks in advanced
Sargus


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

Posted: Sun Feb 11, 2007 9:20 am
by feyd
viewtopic.php?t=62827 could be of interest.

Posted: Sun Feb 11, 2007 9:49 am
by sargus
I go trough the thread twice and seems to me that is different question, with no connection to this one :(

Maybe i could "redesign" main question into how to replace this to use POST method instead GET without having special form for each item :

Code: Select all

    item id 1 
       <a href="script.php?action=edit&id=1"><img src="edit.gif" alt="edit item" /></a>
       <a href="script.php?action=delete&id=1"><img src="delete.gif" alt="edit item" /></a>

    item id 2 
       <a href="script.php?action=edit&id=2"><img src="edit.gif" alt="edit item" /></a>
       <a href="script.php?action=delete&id=2"><img src="delete.gif" alt="edit item" /></a>
and so on

Posted: Sun Feb 11, 2007 9:53 am
by RobertGonzalez
The only way to achieve what you want is to not use an image button or to use a hidden value that is checked instead of the name of the button. Alternatively, you could style the button using an image to make it look like you want. But given the way IE handles image submits, I would tend to stay away from using them.

Posted: Sun Feb 11, 2007 10:45 am
by sargus
Could you please be more specific on that ? I can't see any solution with "hidden value".

I can imagine code like that, but How i will identify what id wass passed without javascript :

Code: Select all

<form action=".." method="post">
    item id 1
        <input type="hidden" name="id" value="1"><!-- or  <input type="hidden" name="id[]" value="1"> -->

        <input type="image" name="edit" value="1" alt="edit " src="..">
        <input type="image" name="delete" value="1" alt="delete" src="..">

    item id 2
       <input type="hidden" name="id" value="2"> <!-- or  <input type="hidden" name="id[]" value="1"> -->
       <input type="image" name="edit" value="2" alt="edit " src="..">
      <input type="image" name="delete" value="2" alt="delete" src="..">
</form> 
and if i leave the image button, and can't see the solution as well, the following could work, but i have to put the id as value..........

Code: Select all

<form action=".." method="post">
   item id 1 <input type="submit" name="edit" value="1"><input type="submit" name="delete" value="1">
   item id 2 <input type="submit" name="edit" value="2"><input type="submit" name="delete" value="2">
</form>
i could style it with background picture of my choice. But when the CSS or pictures ara off i am in trouble again, user will see two buttons with value "1".


Looks like I will have to do form for every items, with hidden "id".

I am not one of the "blame everything on Microsoft", but this time......... :( :evil: