By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

submit form using php code

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
/* 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

P: n/a
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.