About "posting" forms

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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">

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'

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  

Can this be done with just PHP?



Re: About "posting" forms

tony@tony.com wrote:
Quoted text here. Click to load it


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.

Re: About "posting" forms

tony@tony.com wrote:
Quoted text here. Click to load it

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.  

Re: About "posting" forms

Quoted text here. Click to load it

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.


Re: About "posting" forms

Quoted text here. Click to load it

Unless I've failed to understand what you're after, you could use the CURL  
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)...
      $ch = curl_init('https://www.mysite.com/cgi/incoming.php ');
      curl_setopt( $ch, CURLOPT_POST, true );
      curl_setopt( $ch, CURLOPT_POSTFIELDS, 'data01=12&data02=rejected');
      $getinfo_results = curl_getinfo($ch);
      curl_close( $ch );
      $return_page = ob_get_contents();

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


Re: About "posting" forms

tomhartlandREMOV@ETHISgmail.com says...
Quoted text here. Click to load it

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


Re: About "posting" 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.


Site Timeline