Web Analytics Made Easy -
StatCounter Multiple submit button Problem - CodingForum

Announcement

Collapse
No announcement yet.

Multiple submit button Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple submit button Problem

    I'm trying to send a form using the several submit buttons. Each button does something different. One button saves the information to the database, another sends the information via email to people. When I choose to send the information by e-mail I need to ask them to confirm their decision.

    This all works however, I send the form elements to another page which in turn tries to determine which button you pressed and then carries out the necessary actions. I haven't yet been able to get everything working together harmoniously yet and my experience says it has something to do with how I'm determining which button on the form was pressed.

    My form buttons look like this:

    Code:
    <input type='submit' name='sendEmail' value='Send E-mail' onClick='confirmit();return false'>
    
    <input type='submit' name='saveDraft' value='Save Draft'>
    The way I determine which button was pressed is this:

    PHP Code:
    if($saveDraft!=""){
       
    //perform actions
    }
    if(
    $sendEmail!=""){
       
    //perform actions

    I was also wondering maybe there is a better way to determine which button was pressed. If there is a way to set a variable on the fly in an onClick event or something. If I can do that and send it in the form I could test for it on the other side. Does anybody know how to do this?

  • #2
    You posted in the wrong forum. It should be in the PHP forum. Wait for the moderator to move this post there.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      but my question has more to do with html and javascript. The php is just how I'm using the form variables.

      Comment


      • #4
        Originally posted by reub77
        but my question has more to do with html and javascript. The php is just how I'm using the form variables.
        You didn't read the sticky threads at the top of this forum did you?
        Spookster
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment


        • #5
          Originally posted by glenngv
          You posted in the wrong forum. It should be in the PHP forum. Wait for the moderator to move this post there.
          technically, we're supposed to delete questions that get posted here, simply because there are so many of them. the rule isn't enforced as strictly as i'd like, though.

          in this particular case, since it's already been mentioned that the thread'll be moved, i'll move it, and not delete. but keep in mind for the future that questions posted here ( here = the Post a JavaScript forum ) get deleted.

          I'm not sure whether this is a javascript question or a php question. i'll move it to the Javascript forum for now, and if it turns into more of a php question once it gets there, i'll move it again.
          Last edited by joh6nn; Feb 26, 2004, 11:37 PM.
          bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

          i am a loser geek, crazy with an evil streak,
          yes i do believe there is a violent thing inside of me.

          Comment


          • #6
            I think it's more of a php question. There is no better way to check if the submit button is checked than doing it on the server-side.
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              well, the way that Reub is doing things now, he's got 2 submit buttons, which may not even be valid code. i'm actually very surprised the form does anything. well, no, let me rephrase. i'd be surprised if it did anything in any non-IE browser.

              my thoughts were that the solution might be to make them standard buttons, and use onClick events. this has it's own problems too, though (i suspect that no submit button is just as invalid as two of them).

              i'm inclined to agree that php is more likely to offer the best solutin, but really, the best solution is the one that works for Reub.

              /me shrugs.
              bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

              i am a loser geek, crazy with an evil streak,
              yes i do believe there is a violent thing inside of me.

              Comment


              • #8
                Originally posted by joh6nn
                well, the way that Reub is doing things now, he's got 2 submit buttons, which may not even be valid code. i'm actually very surprised the form does anything. well, no, let me rephrase. i'd be surprised if it did anything in any non-IE browser.

                my thoughts were that the solution might be to make them standard buttons, and use onClick events. this has it's own problems too, though (i suspect that no submit button is just as invalid as two of them).

                i'm inclined to agree that php is more likely to offer the best solutin, but really, the best solution is the one that works for Reub.

                /me shrugs.
                Do multiple submit buttons really invalidate the page?
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  Originally posted by joh6nn
                  Do multiple submit buttons really invalidate the page?
                  i have no idea. they might. there are some interesting points brought up in favor of multiple submits in the thread you link, but you have to admit there's just as much reason to think that, even if they work, multiple submits are invalid. somebody's gonna have to go ahead and actually validate some multiple submit code, or check and see if the w3c has anything to say about it. i'll try and take a look later on today, but i have a feeling that i'll forget, and someone else will get to it before i do.

                  Reub, i still think that Glenn is right, and you're better off with php in this case. was there a reason you wanted to do it with javascript?
                  Last edited by joh6nn; Feb 27, 2004, 05:58 AM.
                  bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                  i am a loser geek, crazy with an evil streak,
                  yes i do believe there is a violent thing inside of me.

                  Comment


                  • #10
                    I created this page:
                    Code:
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <title>Multiple Submit</title>
                    </head>
                    <body>
                    <form action="#">
                    <p>
                    <input type="submit" name="btnSubmit" value="Submit" />
                    <input type="submit" name="btnUpdate" value="Update" />
                    </p>
                    </form>
                    </body>
                    </html>
                    and checked it with w3c validator and it was found to be perfectly valid.

                    Could you give us some interesting points that you think multiple submits invalidate the page? I'm curious what they are.
                    Glenn
                    vBulletin Mods That Rock!

                    Comment


                    • #11
                      from http://www.w3.org/TR/html4/interact/forms.html#buttons:
                      buttons
                      Authors may create three types of buttons:

                      * submit buttons: When activated, a submit button submits a form. A form may contain more than one submit button.
                      i need to learn to actually think and research things before opening my mouth. having bothered to look at the spec, i realize that not only did i not have any substantial reasons to back me up, but if i had, then they're all pretty well covered in the spec. :-(
                      bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                      i am a loser geek, crazy with an evil streak,
                      yes i do believe there is a violent thing inside of me.

                      Comment


                      • #12
                        You can use a hidden element to carry the information to action page. Like
                        <input type="submit" name="submit1" value="Button 1" onclick="document.YourForm.Hidden1.value='submit1'">
                        <input type="submit" name="submit2" value="Button 2" onclick="document.YourForm.Hidden1.value='submit2'">
                        <input type="hidden" value="" name="Hidden1">
                        Hope it helps.

                        Comment


                        • #13
                          As said in the previous posts, this is easier and better done in the server-side.
                          Glenn
                          vBulletin Mods That Rock!

                          Comment

                          Working...
                          X