Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts

    passing button name and value via submit()?

    Hi all,

    I have written a little bit of PHP which turns this:

    Code:
    <form method="[whatever]" action="[wherever]" name="[form name]">
      <input name="mytextbox" type="text" />
      <confirm name="callback" value="do this" message="Do you really want to do this?" />
      <confirm name="callback" value="do that" message="Do you really want to do that?" />
    </form>
    Into this:

    Code:
    <form method="[whatever]" action="[wherever]" name="[form name]">
      <input name="mytextbox" type="text" />
      <input type="button" onclick=confirmSubmit("callback", "do this", "[form name]", "Do you really want to do this?" />
      <input type="button" onclick=confirmSubmit("callback", "do that", "[form name]", "Do you really want to do that?" />
    </form>
    which uses the following javascript:

    Code:
    <script language="javascript">
    <!--
      function confirmSubmit(bkey, bvalue, fname, confmsg)
      {
        var response;
    
        /*** Need something here to pass bkey and bvalue as a key/value
         *** pair when the form is submitted.
         ***/
    
        if (formname != "")  //The PHP automatically inserts the form name into the function call, or "" if it is not specified.
          {
            response = confirm(confmessage);
    
            if (response == true)
              document.forms[formname].submit();
          }
        else alert("Programming Error - The form needs a name!");
      }
    // -->
    </script>
    This makes it nice and quick for me to stick submit-like buttons into forms that require user confirmation for the form to be submitted.

    *BUT* how can I pass the name and value of what I've called a "confirm" element with the other form data (see the comment in the javascript)?

    What I'd like to see in the callback data ($_REQUEST) from the given example would be:

    Code:
    "mytextbox" => [user inputted value],
    "callback" => [either "do this" or "do that" depending on the source of the confirmation event]
    Any ideas?

    Thanks,
    Mike.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hey, I fixed my own post! Lol!

    Will post solution after my lunch incase anyone else is remotely interested!
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •