Results 1 to 5 of 5

Thread: Problem of html form with multiple submit buttons

  1. #1
    Join Date
    Jun 2009
    Posts
    87

    Problem of html form with multiple submit buttons

    Here is my concern: I have a mini-site which allows making pages. Several users have access to my database. First: authentication, once past this page, it displays the list of existing records and according to the author of said sheets, the possible actions are not the same:

    (I use real names, so I've hidden)
    Here, for example, I am connected with the name D. and if I click Play, it works, I get page I want. Edit and Delete the same. But if I click on Read other lines, I always see the user D

    If I switch users, the problem remains the same. Each button leads to information about the connected user. I also have an Administrator user who can normally do anything (view, edit, delete), but then he saw that the last sheet created (by the user F)

    Here is the form code where there is the list:

    HTML Code:
    <body>
        <form action="modify.php" method="post">
            <table id="list">
                <tr>
                    <th>
                          Title page |
                    </th>
                    <th>
                          Date modified |
                    </th>
                    <th>
                          Author of the page |
                    </th>
                    <th colspan="3">
                          Available actions
                    </th>
                </tr>
        <?php
        $co = new PDO('mysql:host=127.0.0.1;dbname=pwet', $_SESSION['login'], $_SESSION['pwd']); 
       
        $list=$co->query("SELECT id, owner, date_redac, nom FROM page ORDER BY id ASC";); 
        $list->setFetchMode(PDO::FETCH_OBJ); 
        while($tri=$list->fetch()){ 
        ?>
            <?php
                $list_date = $tri->date_redac;
                list($yyyy, $mm, $dd) = explode("-", $list_date);
                $list_date = "$dd-$mm-$yyyy";
            ?>   
                   <tr style="<?php if($user == $tri->owner){
                                    echo "background-color: #b5e2f9;";
                                  }else{
                                    echo "background-color: #ff8c8c;";
                                }
                                if($user == "Administrator";){
                                    echo "background-color: #9cff8c";
                                }?>">
                <?php if($user == $tri->owner || $user == "Administrator";){?>
                <td>
                    <?php echo $tri->name;?>
                </td>
                <td>
                    <?php echo $list_date;?>
                </td>
                <td>
                    <?php echo $tri->owner;?>
                </td>
                <td colspan="3">
                    <input type="hidden" name="id_select" value="<?php echo $tri->id;?>" />
                    <input type="submit" name="save" value="Read" />
                    <input type="submit" name="page_to_modify" value="Edit" />
                    <input type="submit" name="page_to_delete" value="Remove" />
                </td>
            <?php } else { ?>
                <td>
                    <?php echo $tri->name;?>
                </td>
                <td>
                    <?php echo $list_date;?>
                </td>
                <td>
                    <?php echo $tri->owner;?>
                </td>
                <td colspan="3">
                    <input type="submit" name="save" value="Read" />
                </td>
            <?php
            }
        }
        $list->closeCursor(); 
        ?>
                </tr>
            </table>
        </form>
    </body>
    Normally, the id of my statement should be recovered and sent to the next page (modify.php). Is there a transformation of the type of variable to (id which is used in a mysql query to call the correct data based on the id supplied)?

    I doubt that it shits in the multiple submit buttons, but I do not know how to fix it while keeping the layout and the current navigation

    Any ideas?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Problem of html form with multiple submit buttons

    If you do a print_r($_POST); in modify.php, which variables do you see in your form?

  3. #3
    Join Date
    Jun 2009
    Posts
    87

    Re: Problem of html form with multiple submit buttons

    If I click on Read get: "Array ([id_select] => 74 [save] => Read)" and that, whatever the button "Read" on which I click. 74 being the id of the record written by the bilingual connected at that time. If I change my name, I see the id of the ticket he wrote.

    To Change, I: Array ([id_select] => 74 [page_to_modify] => Edit).

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Problem of html form with multiple submit buttons

    I could be wrong, but I think that one should not use form in this case, just the link with variable. (after so visually like buttons, you use <button>this spike)

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Problem of html form with multiple submit buttons

    Your problem is that your hidden field "id_select" is duplicated as many times as you got lines in your table, so I think the browser is sending the first or last, but still the same. putting a name like "id_select []", it would, or else, "id_select" concatenated to the id for "id_select74" for example.

Similar Threads

  1. How to Submit a Form Using JavaScript?
    By Damien25 in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 07:05 AM
  2. Verify the content of the textbox with multiple buttons on Form
    By Gadhadhar in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 02:19 PM
  3. How to submit form without "Submit Button"?
    By AK_Chopra in forum Software Development
    Replies: 3
    Last Post: 10-09-2009, 08:44 AM
  4. Several submit buttons in the same form ?
    By Wiro in forum Software Development
    Replies: 5
    Last Post: 14-02-2009, 10:29 PM
  5. Problem Submit Form in Firefox [javascript]
    By Swetlano in forum Software Development
    Replies: 0
    Last Post: 09-02-2009, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,165,170.39234 seconds with 17 queries