Can PHP Post without a form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry L [in Honolulu]

    Can PHP Post without a form?

    I have a dropdown list dynamically created in a form by PHP from a MySql
    table. This is the only element on the page. For some records there is only
    a single selection, and if that's the case I'd like to just post that and
    go to the next page. Is there a simple way to do that using POST? I know
    how to do it with GET, but don't like the resulting URLs.

    Or is there a simpler method I'm not thinking about?

    Thanks,
    Larry
  • NC

    #2
    Re: Can PHP Post without a form?

    On Jul 20, 4:07 pm, "Larry L [in Honolulu]" <la...@no-place.org>
    wrote:
    >
    I have a dropdown list dynamically created in a form
    by PHP from a MySql table. This is the only element
    on the page. For some records there is only a single
    selection, and if that's the case I'd like to just
    post that and go to the next page. Is there a simple
    way to do that using POST?
    Yes, but it's got nothing to do with PHP:

    <form method="POST" action="[your_action_goe s_here]">
    <select name="mySelect" id="mySelect"
    onChange="mySel ect.form.submit ()">
    <option value="">Select an option
    <option value="1">Optio n 1
    <option value="2">Optio n 2
    <option value="3">Optio n 3
    <option value="4">Optio n 4
    </select>
    </form>

    Cheers,
    NC

    Comment

    • Larry L [in Honolulu]

      #3
      Re: Can PHP Post without a form?

      NC <nc@iname.comwr ote in news:1184973751 .142209.176900
      @d30g2000prg.go oglegroups.com:
      On Jul 20, 4:07 pm, "Larry L [in Honolulu]" <la...@no-place.org>
      wrote:
      >>
      >I have a dropdown list dynamically created in a form
      >by PHP from a MySql table. This is the only element
      >on the page. For some records there is only a single
      >selection, and if that's the case I'd like to just
      >post that and go to the next page. Is there a simple
      >way to do that using POST?
      >
      Yes, but it's got nothing to do with PHP:
      >
      <form method="POST" action="[your_action_goe s_here]">
      <select name="mySelect" id="mySelect"
      onChange="mySel ect.form.submit ()">
      <option value="">Select an option
      <option value="1">Optio n 1
      <option value="2">Optio n 2
      <option value="3">Optio n 3
      <option value="4">Optio n 4
      </select>
      </form>
      >
      Cheers,
      NC
      Well thanks, but maybe I didn't explain it well enough. I have pretty
      much exactly what you show, but sometimes when the page loads, and the
      options list is created, there is only one item there. If that's the
      case, then I don't want to even show it, I just want the one option
      posted to the next page.

      Larry


      Comment

      • Michael Fesser

        #4
        Re: Can PHP Post without a form?

        ..oO(Larry L [in Honolulu])
        >Well thanks, but maybe I didn't explain it well enough. I have pretty
        >much exactly what you show, but sometimes when the page loads, and the
        >options list is created, there is only one item there. If that's the
        >case, then I don't want to even show it, I just want the one option
        >posted to the next page.
        In short: What kind of informations do you want to post to the next
        page?

        A bit longer: Sending a form to the client, just to have it posted back
        immediately is not only really ugly, but also highly unreliable, since
        it requires JavaScript. Dependent on the informations that have to be
        sent around, there might be better ways (e.g. a server-side redirect,
        sessions, CURL, ...)

        Micha

        Comment

        • Jeff North

          #5
          Re: Can PHP Post without a form?

          On 21 Jul 2007 00:30:17 GMT, in comp.lang.php "Larry L [in Honolulu]"
          <larry@no-place.org>
          <46a15399$0$205 94$4c368faf@roa drunner.comwrot e:
          >| NC <nc@iname.comwr ote in news:1184973751 .142209.176900
          >| @d30g2000prg.go oglegroups.com:
          >|
          >| On Jul 20, 4:07 pm, "Larry L [in Honolulu]" <la...@no-place.org>
          >| wrote:
          >| >>
          >| >I have a dropdown list dynamically created in a form
          >| >by PHP from a MySql table. This is the only element
          >| >on the page. For some records there is only a single
          >| >selection, and if that's the case I'd like to just
          >| >post that and go to the next page. Is there a simple
          >| >way to do that using POST?
          >| >
          >| Yes, but it's got nothing to do with PHP:
          >| >
          >| <form method="POST" action="[your_action_goe s_here]">
          >| <select name="mySelect" id="mySelect"
          >| onChange="mySel ect.form.submit ()">
          >| <option value="">Select an option
          >| <option value="1">Optio n 1
          >| <option value="2">Optio n 2
          >| <option value="3">Optio n 3
          >| <option value="4">Optio n 4
          >| </select>
          >| </form>
          >| >
          >| Cheers,
          >| NC
          >|
          >| Well thanks, but maybe I didn't explain it well enough. I have pretty
          >| much exactly what you show, but sometimes when the page loads, and the
          >| options list is created, there is only one item there. If that's the
          >| case, then I don't want to even show it, I just want the one option
          >| posted to the next page.
          >|
          >| Larry
          PHP Manual example:
          <?php
          $link = mysql_connect(" localhost", "mysql_user ", "mysql_password ");
          mysql_select_db ("database", $link);

          $result = mysql_query("SE LECT * FROM table1", $link);
          $num_rows = mysql_num_rows( $result);

          echo "$num_rows Rows\n";
          ?>

          instead of echoing the number you would use
          if( $num_rows == 1 )
          header("locatio n: pag2.php");

          This is provided you haven't sent any information to the browser
          already.
          -- -------------------------------------------------------------
          jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
          -- -------------------------------------------------------------

          Comment

          • Michael Fesser

            #6
            Re: Can PHP Post without a form?

            ..oO(Jeff North)
            >instead of echoing the number you would use
            >if( $num_rows == 1 )
            > header("locatio n: pag2.php");
            header("Locatio n: http://{$_SERVER['HTTP_HOST']}/pag2.php");

            The URL must be absolute.

            Micha

            Comment

            • Jerry Stuckle

              #7
              Re: Can PHP Post without a form?

              Larry L [in Honolulu] wrote:
              I have a dropdown list dynamically created in a form by PHP from a MySql
              table. This is the only element on the page. For some records there is only
              a single selection, and if that's the case I'd like to just post that and
              go to the next page. Is there a simple way to do that using POST? I know
              how to do it with GET, but don't like the resulting URLs.
              >
              Or is there a simpler method I'm not thinking about?
              >
              Thanks,
              Larry
              If you really need to post the forum, check CURL.

              OTOH, I might recommend you store the appropriate info in a session, and
              change the target page to look for the data in the session, also.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Larry L [in Honolulu]

                #8
                Re: Can PHP Post without a form?

                Jerry Stuckle <jstucklex@attg lobal.netwrote in
                news:ydydnRgtRt e14DzbnZ2dnUVZ_ qDinZ2d@comcast .com:
                OTOH, I might recommend you store the appropriate info in a session,
                and change the target page to look for the data in the session, also.
                >
                Thanks Jerry, ultimately that's what I did, it took me a while to realize I
                already had a session open which made it pretty easy.

                Larry

                Comment

                • bill

                  #9
                  Re: Can PHP Post without a form?

                  Michael Fesser wrote:
                  .oO(Jeff North)
                  >
                  >instead of echoing the number you would use
                  >if( $num_rows == 1 )
                  > header("locatio n: pag2.php");
                  >
                  header("Locatio n: http://{$_SERVER['HTTP_HOST']}/pag2.php");
                  >
                  The URL must be absolute.
                  why ?

                  bill

                  Comment

                  • Andy Hassall

                    #10
                    Re: Can PHP Post without a form?

                    On Sat, 21 Jul 2007 09:30:30 -0400, bill <nobody@spamcop .netwrote:
                    >Michael Fesser wrote:
                    >.oO(Jeff North)
                    >>
                    >>instead of echoing the number you would use
                    >>if( $num_rows == 1 )
                    >> header("locatio n: pag2.php");
                    >>
                    >header("Locati on: http://{$_SERVER['HTTP_HOST']}/pag2.php");
                    >>
                    >The URL must be absolute.
                    >
                    >why ?
                    HTTP/1.1 section 14.30.


                    --
                    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
                    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

                    Comment

                    • Toby A Inkster

                      #11
                      Re: Can PHP Post without a form?

                      bill wrote:
                      Michael Fesser wrote:
                      >
                      >header("Locati on: http://{$_SERVER['HTTP_HOST']}/pag2.php");
                      >The URL must be absolute.
                      >
                      why ?
                      HTTP/1.1 spec says so.

                      Most browsers do support relative URLs in Location headers, but it's unwise
                      to rely on that.

                      --
                      Toby A Inkster BSc (Hons) ARCS
                      [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
                      [OS: Linux 2.6.12-12mdksmp, up 30 days, 17:58.]

                      Parsing an HTML Table with PEAR's XML_HTTPSax3

                      Comment

                      • bill

                        #12
                        Re: Can PHP Post without a form?

                        Toby A Inkster wrote:
                        bill wrote:
                        >Michael Fesser wrote:
                        >>
                        >>header("Locat ion: http://{$_SERVER['HTTP_HOST']}/pag2.php");
                        >>The URL must be absolute.
                        >why ?
                        >
                        HTTP/1.1 spec says so.
                        >
                        Most browsers do support relative URLs in Location headers, but it's unwise
                        to rely on that.
                        >
                        Thanks to you both.

                        Comment

                        • Sanders Kaufman

                          #13
                          Re: Can PHP Post without a form?

                          Larry L [in Honolulu] wrote:
                          I have a dropdown list dynamically created in a form by PHP from a MySql
                          table. This is the only element on the page. For some records there is only
                          a single selection, and if that's the case I'd like to just post that and
                          go to the next page. Is there a simple way to do that using POST? I know
                          how to do it with GET, but don't like the resulting URLs.
                          >
                          Or is there a simpler method I'm not thinking about?
                          >
                          Thanks,
                          Larry
                          You're looking for a Javascript solution - client side, you know.
                          There's a submit() function that you can programatically fire in JS to
                          have the page submit a form.

                          <a href="javascrip t:submit();">Su bmit</a>

                          It'll retain that hyperlink look and feel, but actually be a post
                          instead of a get.




                          Comment

                          Working...