More than one submit to set a redirect variable with PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JS

    #1

    More than one submit to set a redirect variable with PHP

    I have a series of pages which make up a questionnaire. It's all done
    in PHP and I'd like to have two submit buttons (well, images really) so
    that one submits the form and takes them to the next page, the other
    submits the form and takes them to the previous page.

    The redirect value is set using PHP so I'd like some Javascript to set
    that variable, then submit the form so that I can accomplish this
    requirement.

    Is this possible? I know Javascript can submit a form, and also can
    send a variable to a PHP script, but I'm not sure how to do this
    combination.

    Thanks in advance.

    Jon

  • micha

    #2
    Re: More than one submit to set a redirect variable with PHP

    why not use javascript to fill in a hidden field, like this:

    document.getEle mentByName('you r_hidden_field' ).value='some_v alue';
    document.your_f orm.submit();

    you get $_POST/$_GET['your_hidden_fi eld'] = 'some_value' in php

    micha

    Comment

    • RobB

      #3
      Re: More than one submit to set a redirect variable with PHP

      JS wrote:[color=blue]
      > I have a series of pages which make up a questionnaire. It's all done
      > in PHP and I'd like to have two submit buttons (well, images really)[/color]
      so[color=blue]
      > that one submits the form and takes them to the next page, the other
      > submits the form and takes them to the previous page.
      >
      > The redirect value is set using PHP so I'd like some Javascript to[/color]
      set[color=blue]
      > that variable, then submit the form so that I can accomplish this
      > requirement.
      >
      > Is this possible? I know Javascript can submit a form, and also can
      > send a variable to a PHP script, but I'm not sure how to do this
      > combination.
      >
      > Thanks in advance.
      >
      > Jon[/color]

      Just use two graphical submit 'buttons':

      <input type="image" src="..." name="back" value="true" />
      <input type="image" src="..." name="fwd" value="true" />

      Be aware that when you fish that element name out at the server it'll
      be in the format:

      back.x [or] back.y

      ....as the clickpoint is sent along, kind of a $0.98 image map. Gecko
      posts the name/value pair by itself as well.

      Comment

      • JS

        #4
        Re: More than one submit to set a redirect variable with PHP

        Excellent, very fast response. Many thanks, I'll give your tips a go
        and let you know how I get on.

        Comment

        • JS

          #5
          Re: More than one submit to set a redirect variable with PHP

          Hi again

          Couldn't get micha's suggestion to work but managed to modify it
          successfully:

          javascript:docu ment.form1.redi rect_page.value ='page04.php';d ocument.form1.s ubmit();

          It's working fine in IE6. Have I breached any rules that could cause
          problems?

          Thanks again.

          Comment

          • JS

            #6
            Re: More than one submit to set a redirect variable with PHP

            Very fast response. Many thanks, I'll give your suggestions a go and
            let you know.

            Comment

            • RobB

              #7
              Re: More than one submit to set a redirect variable with PHP

              JS wrote:[color=blue]
              > Hi again
              >
              > Couldn't get micha's suggestion to work but managed to modify it
              > successfully:
              >
              >[/color]
              javascript:docu ment.form1.redi rect_page.value ='page04.php';d ocument.form1.s ubmit();[color=blue]
              >
              > It's working fine in IE6. Have I breached any rules that could cause
              > problems?[/color]

              Yes. Never submit a form programmaticall y - with JavaScript - if you
              can help it. No JS, no form.

              Comment

              • JS

                #8
                Re: More than one submit to set a redirect variable with PHP

                Thanks RobB. I do have a standard submit button at the bottom of the
                form too which just takes you to the next page so I guess having the JS
                for Prev...Next isn't such a problem. I'm intrigued by your solution
                with the image buttons but am unclear how to actually implement it.

                Comment

                Working...