SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Multiple Reply Buttons

    At the top of my "Display Private Message" page, I have a "Reply" Form Button that users can click on to respond to the PM. There is also a "Delete" Form Button like this...
    HTML Code:
    	<div id='commandBar'>
    		<input type='submit' name='submit' value='Reply'/>
    		<input type='submit' name='submit' value='Delete'/>
    	</div>

    By naming each Form Button "submit", it streamlines my PHP code, because when the Form is submitted, my code always knows to look for the value assigned to "submit" like this...
    PHP Code:
            if ($_POST['submit']=="Reply"){
                
    // Do some reply stuff...
            
    }elseif ($_POST['submit']=="Delete"){
                
    // Do some delete stuff...
            


    (Someone taught me this technique, and it is way easier to manage than having different names for each Button.)

    However, my problem is that I want to add a second set of "Reply" and "Delete" Form Buttons at the bottom of my "Display Private Message" page so Users don't have to scroll to the top of the page on long messages.

    If I use the same code above I will have two sets of Form Submit Buttons with *duplicate values*...

    And if I give each set of Buttons unique Values, then that screws up the Button Label. (It would look silly to have "Reply" and "Delete" at the top of the page, and "Reply2" and "Delete2" at the bottom of the page?!)

    Is there a way to accomplish what I want, and hopefully not have to change the scheme I am currently using?

    Sincerely,


    Debbie

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    If the buttons do exactly the same (so you don't need to discern them in PHP) there is no problem with giving them the same value.
    You can't give elements the same name or id, but you can re-use values as many times as you like (otherwise it wouldn't be possible to have multiple checkboxes on a page, for starters).
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,934
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    If the buttons do exactly the same (so you don't need to discern them in PHP) there is no problem with giving them the same value.

    You can't give elements the same name or id, but you can re-use values as many times as you like (otherwise it wouldn't be possible to have multiple checkboxes on a page, for starters).
    Well, you can obviously have multiple Buttons with the same name because that is what I am currently doing...

    But I guess you are saying having this...
    HTML Code:
    	<div id='commandBar'>
    		<input type='submit' name='submit' value='Reply'/>
    		<input type='submit' name='submit' value='Delete'/>
    	</div>
    ...in TWO PLACES isn't an issue if they point to the same PHP code?


    Debbie

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Ah yes, you can indeed have elements with the same name, my bad. The latter just overrides the former in case of regular inputs and in case of submits it sends the value of the one that was clicked (as described here).

    And yes, that's what I was saying [that it isn't an issue to put the same value in multiple places as long as they point to the same PHP code].
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •