submit form using php code

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

Threaded View

hello friends

i have one php script which generates html page containing form. what i
want is submit this form using php script.

pls give me some idea that how can i submit form using php code. it is
possible to submit form using javascript or vbscript but i am not
allowed to use javascript or vbscript in my project. so how can i do it
using php code??

thxs for your help in advance......

Re: submit form using php code

 /* sendToHost
 * ~~~~~~~~~~
 * Params:
 *   $host      - Just the hostname.  No http:// or
                  /path/to/file.html portions
 *   $method    - get or post, case-insensitive
 *   $path      - The /path/to/file.html part
 *   $data      - The query string, without initial question mark
 *   $useragent - If true, 'MSIE' will be sent as
                  the User-Agent (optional)
 * Examples:
 *   sendToHost('">','get','/search','q=php_imlib');
 *   sendToHost('','post','/some_script.cgi',
 *              'param=First+Param&second=Second+param');

function SendToHost($host,$method,$path,$data,$useragent=0)
 // Supply a default method of GET if the one passed was empty
 if (empty($method))
  $method = 'GET';
 $method = strtoupper($method);
 $fp = fsockopen($host,80);
 if ($method == 'GET')
  $path .= '?' . $data;
 fputs($fp, "$method $path HTTP/1.1\n");
 fputs($fp, "Host: $host\n");
 fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
 fputs($fp, "Content-length: " . strlen($data) . "\n");
 if ($useragent)
  fputs($fp, "User-Agent: MSIE\n");
 fputs($fp, "Connection: close\n\n");
 if ($method == 'POST')
  fputs($fp, $data);

 while (!feof($fp))
  $buf .= fgets($fp,128);
 return $buf;


Re: submit form using php code

vishal wrote:
Quoted text here. Click to load it

You simply can't, because PHP is rendered on the server and sends the result
back to the browser. All interaction, like submitting a form, should be
handled by the client (by pressing a button or by using client-side
scripting). One question you could ask yourself, is when you want to
auto-submit a form generated by PHP, why generating the form at all and not
just process the input data at once?

When the goal of the form is to gather additional information (which it
usual is), just leave it up to the user to press the submit button when done
providing the required information.


Site Timeline