1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to tell which FORM button was pushed?

Discussion in 'PHP' started by tigermedia_ca, Nov 29, 2007.

  1. #1
    I have been ripping my hair out for days trying to figure out how to make this work without javascript (although that's something that CAN be used if necessary).

    I have a form with a SAVE and DELETE button required in the same form (they share the same fields and information).

    What I want to be able to do is be able to tell WHICH button was pushed. via $_POST would be great, but I dont' know if its possible.

    This is what I have, and it does not pass a value for "save" or "delete":


    <input type=image src=save.gif border=0 name=save alt='Save Trade Settings' value='true'>
    <input type=image src=delete.gif border=0 name=delete alt='Delete This Trade' value='true'>

    Any help, please...
     
    tigermedia_ca, Nov 29, 2007 IP
  2. Lindsey2002

    Lindsey2002 Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't really understand what is the problem if your button have two different id's....
    you give them two different id's and then set up the $_post to take a variable from whichever of them you want.

    no?
     
    Lindsey2002, Nov 29, 2007 IP
  3. tigermedia_ca

    tigermedia_ca Active Member

    Messages:
    402
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    70
    #3
    That's what I thought too.

    if($_POST[save] == "true"){do this}
    elseif($_POST[delete] == "true"){do that}

    But this DOES NOT seem to work.
     
    tigermedia_ca, Nov 29, 2007 IP
  4. Elad-A

    Elad-A Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <input type = "submit" name = "save" value = "Save" />
    
    <input type = "submit" name = "delete" value = "Delete" />
    
    
    Code (markup):
    
    if($_POST['save'] || $_POST['save'] == 'Save')
    {
    	do .....
    }
    
    if($_POST['delete'] || $_POST['delete'] == 'Delete')
    {
    	do .....
    }
    
    PHP:
     
    Elad-A, Nov 29, 2007 IP
  5. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #5
    Try this
    
    <input type=image src=save.gif border=0 name=action[] alt='Save Trade Settings' value='true'>
    <input type=image src=delete.gif border=0 name=action[]alt='Delete This Trade' value='true'>
    PHP:
    by placing the two action buttons in an array the one pushed will be passed with the post data, $_POST[action][0][true]
    might be best to use the value's as save and delete rather that true make it easyier for comparsion
    Hope this what you require
     
    Big 'G', Nov 29, 2007 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    You have two ways to solve your problem.

    * Using img submits, which when are clicked, send an X/Y variable of where it was clicked.
    * Create a hidden field, when users click on delete, you change the original value of 0 to 1, and you process the form based on that hidden field. If user has Javascript off (small possibility), the item will not get removed, or maybe give the user a message to turn it on.

    Peace,
     
    Barti1987, Nov 30, 2007 IP
  7. tigermedia_ca

    tigermedia_ca Active Member

    Messages:
    402
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    70
    #7

    The hidden field idea was one that I played with but I don't know javascript well enough to dynamically change that field based on the button push, is there an EXTREMELY simple script that will do this for me that someone can share?

    I haven't had time to try any of these yet, I leave on Vacation in less than 24hrs.
     
    tigermedia_ca, Nov 30, 2007 IP