PHP form that doesn't require a submit button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #16
    Heya, Chazzy.

    You have to make your header() calls before your script outputs anything.

    Comment

    • chazzy69
      New Member
      • Sep 2007
      • 196

      #17
      Sorry not quite what im looking for; as stated above it is NOT a form i require (so there is no actual user input at all) But a method for posting data from one page to another without using a form and a method for receive that data on the other page.

      Thanks for the help though

      Comment

      • chazzy69
        New Member
        • Sep 2007
        • 196

        #18
        Originally posted by pbmods
        Heya, Chazzy.

        You have to make your header() calls before your script outputs anything.
        Ok i will check this out

        Comment

        • chazzy69
          New Member
          • Sep 2007
          • 196

          #19
          In reply to the Using the header, thanks to pbmods, the function actuall works as long as you post the data before you output anything.

          Now how would i go about receive the data sent with this header function??

          Thanks

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #20
            If you do something like this:
            [code=php]
            header("locatio n:abc.php?usern ame=xyz");
            [/code]

            The User's browser will create a new request to abc.php. You can access username in this case via $_GET, just like any other request:

            [code=php]
            echo $_GET['username']; // xyz
            [/code]

            Comment

            • chazzy69
              New Member
              • Sep 2007
              • 196

              #21
              I think possible i going about this the wrong way. I want one page of code to run through and finish, then in the last few lines open up the next page of code to run though but in opening of the page send a couple of varibles to it.

              The closest thing i knew of was a php form with a submit button hence the title, but mabye im going in the wrong direction????

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #22
                Using a header() redirect does create a new request. It would be equivalent to submitting a new form whose method="get".

                The way HTTP works is the server sends headers right before the content of a page.

                When the browser receives these headers, it processes them in various ways (for example, a 'Content-type' header tells the browser what sort of data comes after the headers [might be HTML or binary data or a JPEG image, etc.]).

                When the browser sees a 'Location' header, it stops what it is doing and sends a new request.

                So when you call [code=php]header("locatio n:abc.php?usern ame=xyz");[/code] you are literally telling the browser, "send over a new request for abc.php and set username to xyz."

                This should do what you are looking for; the only gotcha is that you'll have to reference $_GET instead of $_POST.

                The only other way to accomplish what you want is to compartmentaliz e your functionality using functions and classes so that you can combine the two files into one.

                Comment

                • chazzy69
                  New Member
                  • Sep 2007
                  • 196

                  #23
                  Thanks i will do a little research into this, also i read above "valajio" mentioning that that javascript can be used to automatically post a form on a certain event, is there anyway possible this could be done without javascript but with purely php because i don't really want the user to be able to accidently blocking the send form.

                  Or if not some way in which the javascript would be executed on the server but not in the users browser to limit what they can see


                  Thanks for all you help everyone

                  Comment

                  • pbmods
                    Recognized Expert Expert
                    • Apr 2007
                    • 5821

                    #24
                    PHP cannot directly interface with HTML the way you need it to. PHP is executed on the server and generates the HTML and JavaScript that the browser then executes. The browser never sees a single line of PHP code.

                    The only option there is to submit the form using JavaScript, e.g.:
                    [code=javascript]
                    document.getEle mentById('theFo rm').submit();
                    [/code]

                    Comment

                    • nse111
                      New Member
                      • Jul 2008
                      • 21

                      #25
                      ok here's soemthing you can do to pass a value using a variable from one php file to another:

                      [code=php]
                      file1.php
                      <?php
                      $name="Diana";
                      ?>

                      file2.php
                      <?php
                      include("file1. php");
                      echo "$name";
                      ?>[/code]

                      here if u execute file2.php file you will see the value "Diana" on the screen.
                      Hope this will help! :)

                      Comment

                      • chazzy69
                        New Member
                        • Sep 2007
                        • 196

                        #26
                        Originally posted by nse111
                        ok here's soemthing you can do to pass a value using a variable from one php file to another:

                        [code=php]
                        file1.php
                        <?php
                        $name="Diana";
                        ?>

                        file2.php
                        <?php
                        include("file1. php");
                        echo "$name";
                        ?>[/code]

                        here if u execute file2.php file you will see the value "Diana" on the screen.
                        Hope this will help! :)
                        Thank you very much this is exactly what is was looking for!!!!

                        Comment

                        Working...