469,641 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,641 developers. It's quick & easy.

submit form using php code

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

Jul 17 '05 #1
2 3747
/* 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('www.google.com','get','/search','q=php_imlib');
* sendToHost('www.example.com','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);
fclose($fp);
return $buf;

}

Jul 17 '05 #2
vishal wrote:
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??


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.
JW

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bruce Duncan | last post: by
6 posts views Thread by CJM | last post: by
4 posts views Thread by Dmitry Korolyov [MVP] | last post: by
4 posts views Thread by j1dopeman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.