how to use form with two buttons

Discussion in 'PHP' started by kharearch, Jan 18, 2008.

  1. #1
    I have a form on which I have two buttons 'add' and 'delete'. I have to take seperate action for both of the button. How can I do that. Please give an example.
     
    kharearch, Jan 18, 2008 IP
  2. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    maybe it will help

    make to submit button like these:
    <FORM method="post" action="filter.php">
    
    <INPUT name="submitAsAdd" type="submit" value="Add">
    <INPUT name="submitAsDelete" type="submit" value="delete">
    
    </FORM>
    
    PHP:
    and then make a filter file to check what the angine has to do and redirect it to the processor file.

    //filter.php:
    <?PHP
    if ($_POST[submitAsAdd])
    {
    header ("location:add.php");
    }
    if ($_POST[submitAsDelete])
    {
    header ("location:delete.php");
    }
    ?>
    PHP:
    i hope it helps
     
    junandya, Jan 18, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Don't forget the quotes around your array index names. And also use isset() to avoid E_NOTICES.
     
    nico_swd, Jan 18, 2008 IP
  4. junandya

    junandya Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    @nico_swd: is that different between i use ' or "? and then where should i state the isset()?
     
    junandya, Jan 18, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    nico_swd, Jan 18, 2008 IP
  6. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #6
    You can use Get also in place of post but that will make it more unsecure

    Regards

    Alex
     
    kmap, Jan 18, 2008 IP
  7. james_r

    james_r Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    hey junandya, thanks for the idea.. I've often dealt with that problem with javascript on the form page to set a new action on the form, but I think I will use this way in the future, it seems much easier :) Thanks!
     
    james_r, Jan 18, 2008 IP
  8. Denn

    Denn Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It is really James_r
     
    Denn, Jan 19, 2008 IP