About "posting" forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tony@tony.com

    About "posting" forms


    Is it possible to use the post method to send a form from PHP without
    having to put the form in a html page?

    <form action="https://www.mysite.com/cgi/incoming.php" method="post">
    <input type="hidden" name="data01" value="12">
    <input type="hidden" name="data02" value="rejected ">
    <input type="hidden" name="star" value="sirius">
    <input type="image" src="https://www.mysite.com/grid001/image1.gif"
    border="0" name="submit" alt="send data">
    </form>

    What I would like to do is make the use of this form as invisible to the
    user as possible by

    1. getting rid of the image (but then how do I "post" it)
    2. putting PHP variables into the value fields
    3. send the form

    The PHP variables are set up as in
    $data01 = 12;
    $data02 = 'rejected'
    etc
    then

    after just including it as in "include_once(' senddata.php'); the form
    above is in senddata.php and just gets posted

    I've been looking at this and can't see how without having to include the
    form on a html page. I looked at document.write but that again is
    javascript.

    Can this be done with just PHP?

    thanks

    tony


  • Jerry Stuckle

    #2
    Re: About &quot;posting&q uot; forms

    tony@tony.com wrote:[color=blue]
    > Is it possible to use the post method to send a form from PHP without
    > having to put the form in a html page?
    >
    > <form action="https://www.mysite.com/cgi/incoming.php" method="post">
    > <input type="hidden" name="data01" value="12">
    > <input type="hidden" name="data02" value="rejected ">
    > <input type="hidden" name="star" value="sirius">
    > <input type="image" src="https://www.mysite.com/grid001/image1.gif"
    > border="0" name="submit" alt="send data">
    > </form>
    >
    > What I would like to do is make the use of this form as invisible to the
    > user as possible by
    >
    > 1. getting rid of the image (but then how do I "post" it)
    > 2. putting PHP variables into the value fields
    > 3. send the form
    >
    > The PHP variables are set up as in
    > $data01 = 12;
    > $data02 = 'rejected'
    > etc
    > then
    >
    > after just including it as in "include_once(' senddata.php'); the form
    > above is in senddata.php and just gets posted
    >
    > I've been looking at this and can't see how without having to include the
    > form on a html page. I looked at document.write but that again is
    > javascript.
    >
    > Can this be done with just PHP?
    >
    > thanks
    >
    > tony
    >
    >[/color]

    Tony,

    A form is an html construct - so not being in an html page is meaningless.

    Maybe if you tell us exactly what you're trying to accomplish we can give you
    other ideas.


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

    Comment

    • Paul Lautman

      #3
      Re: About &quot;posting&q uot; forms

      tony@tony.com wrote:[color=blue]
      > Is it possible to use the post method to send a form from PHP without
      > having to put the form in a html page?
      >
      > <form action="https://www.mysite.com/cgi/incoming.php" method="post">
      > <input type="hidden" name="data01" value="12">
      > <input type="hidden" name="data02" value="rejected ">
      > <input type="hidden" name="star" value="sirius">
      > <input type="image" src="https://www.mysite.com/grid001/image1.gif"
      > border="0" name="submit" alt="send data">
      > </form>
      >
      > What I would like to do is make the use of this form as invisible to
      > the user as possible by
      >
      > 1. getting rid of the image (but then how do I "post" it)
      > 2. putting PHP variables into the value fields
      > 3. send the form
      >
      > The PHP variables are set up as in
      > $data01 = 12;
      > $data02 = 'rejected'
      > etc
      > then
      >
      > after just including it as in "include_once(' senddata.php'); the form
      > above is in senddata.php and just gets posted
      >
      > I've been looking at this and can't see how without having to include
      > the form on a html page. I looked at document.write but that again is
      > javascript.
      >
      > Can this be done with just PHP?
      >
      > thanks
      >
      > tony[/color]

      The POST method is used to send data from a web page to the server so that
      you can use it in things like php variables.
      You don't need an image or even a button to submit a form. A text input box
      will work to submit a form just by pressing the enter key.
      What you need to do is to explain what you ultimately want to happen.


      Comment

      • Tom

        #4
        Re: About &quot;posting&q uot; forms


        <tony@tony.co m> wrote in message
        news:MPG.1ef0bd 3b934f949c9898c 5@news-text.blueyonder .co.uk...[color=blue]
        >
        > Is it possible to use the post method to send a form from PHP without
        > having to put the form in a html page?[/color]

        Unless I've failed to understand what you're after, you could use the CURL
        library.
        It allows you to call any web page (not necessarily a PHP page) from within
        your PHP.
        Make sure the "extension=php_ curl.dll" is uncommented in your PHP.ini.

        Something like this (which uses buffering to stop the returned web page
        being displayed)...
        ob_start();
        $ch = curl_init('http s://www.mysite.com/cgi/incoming.php');
        curl_setopt( $ch, CURLOPT_POST, true );
        curl_setopt( $ch, CURLOPT_POSTFIE LDS, 'data01=12&data 02=rejected');
        curl_exec($ch);
        $getinfo_result s = curl_getinfo($c h);
        curl_close( $ch );
        $return_page = ob_get_contents ();
        ob_end_clean();

        "$getinfo_resul ts" will give an array of information telling you if the page
        request was successful or not, and "$return_pa ge" will contain the full HTML
        of the request.

        Tom


        Comment

        • tony@tony.com

          #5
          Re: About &quot;posting&q uot; forms

          In article <4ensg4F1fdeu6U 1@individual.ne t>, paul.lautman@bt internet.com
          says...[color=blue]
          > tony@tony.com wrote:[color=green]
          > > Is it possible to use the post method to send a form from PHP without
          > > having to put the form in a html page?
          > >
          > > <form action="https://www.mysite.com/cgi/incoming.php" method="post">[/color][/color]
          [color=blue]
          > What you need to do is to explain what you ultimately want to happen.
          >[/color]

          I'm sorry I assumed you could see what I want to do by looking at the
          form action I posted

          I want to send the data to another web server as if it had been posted
          using the forms post method without having the form appear in the source
          of the clients web page.

          Looking at it another way I want to "post" the data without using the
          form but it MUST be using the "post" method because thats how the
          reciever is set up and I cant control that.

          I already have the data I just want to use the post method to send it
          without the client getting it as well.

          I hope that explains it - I can't think of a way to say it any clearer.

          tony




          Comment

          • tony@tony.com

            #6
            Re: About &quot;posting&q uot; forms

            In article <44870369$0$229 25$ed2619ec@ptn-nntp-reader01.plus.n et>,
            tomhartlandREMO V@ETHISgmail.co m says...[color=blue]
            >
            > <tony@tony.co m> wrote in message
            > news:MPG.1ef0bd 3b934f949c9898c 5@news-text.blueyonder .co.uk...[color=green]
            > >
            > > Is it possible to use the post method to send a form from PHP without
            > > having to put the form in a html page?[/color]
            >
            > Unless I've failed to understand what you're after, you could use the CURL
            > library.
            > It allows you to call any web page (not necessarily a PHP page) from within
            > your PHP.
            > Make sure the "extension=php_ curl.dll" is uncommented in your PHP.ini.
            >
            > Something like this (which uses buffering to stop the returned web page
            > being displayed)...
            > ob_start();
            > $ch = curl_init('http s://www.mysite.com/cgi/incoming.php');
            > curl_setopt( $ch, CURLOPT_POST, true );
            > curl_setopt( $ch, CURLOPT_POSTFIE LDS, 'data01=12&data 02=rejected');
            > curl_exec($ch);
            > $getinfo_result s = curl_getinfo($c h);
            > curl_close( $ch );
            > $return_page = ob_get_contents ();
            > ob_end_clean();
            >
            > "$getinfo_resul ts" will give an array of information telling you if the page
            > request was successful or not, and "$return_pa ge" will contain the full HTML
            > of the request.
            >
            > Tom
            >
            >
            >[/color]

            Hi Tom - I think you do get the idea (from your buffering comment)
            I've never heard of curl (I'm just getting over wasting loads of my time
            with that pear rubbish)

            I'll take a look at curl (assuming my service provider allows its use -
            these people are very daft about what they do and dont allow sometimes)

            thanks for the idea

            tony

            Comment

            • tony@tony.com

              #7
              Re: About &quot;posting&q uot; forms - An update for anyone interested


              It turns out that you can use the Post method to send data as if it came
              from a form easy enough - no other libraries etc are needed.

              Just create a php script that writes a "POST" header then url encode what
              would have been the form items names and values as the body and then use
              PHP's fsockopen to send the data.

              The remote end thinks it came from a form which is exactly what I needed.

              Hope this helps anyone reading this.

              tony

              Comment

              Working...