We help IT Professionals succeed at work.

Get CGI Form contain variable and email it

anakecil asked
Medium Priority
Last Modified: 2010-04-06
I wanna know how to get the number or string on each text area or radio button from form variables. Also how can I send them in simple structured format to my email account.All should created on CGI-BIN Delphi2 with NT 4.0 server only using IIS.YGOLAN already give me guide on how to get environment variable on QUERY_STRING, but I really only get the thingy beside the cgi.exe?xxx=xxx string, but I want to get the strings which we can get from user input when they submit their form.For example I have a query text area asking about user name, and a button for submit it. So what should I do in both HTML and CGI program also how can I send it to my email so I canalerted that user has input their data ??below HTML is what I do now please confirm if there should any change on it :<Form Action="/cgi-bin/cgi.exe" method="post">Your name:<BR><input type="text" name="name"><p><input type="submit" value="ok"></form>Also what I really want received at my email is formated like this below :Name : user_namethats all folks thxx for your attentionI'll appreciate your help.
Watch Question

This isn't a answer to your question, but :
Have you tried ISAPI instead of CGI?



Thxx for your comment crb, if I can use ISAPI, I will, but I don't know how since I'm newbies on Delphi and website programming.-AnaKecil -

I am not sure if I'am right but I think the server executes ISAPI's faster and you will get some nice functions :)



Yes you right I guess, thought I'm not yet even know about how to program on ISAPI thingy, but I'm sure ISAPI better than CGI since that's why microsoft create it for standard and borland also supported it on Delphi 3. But the thing is my delphi is ver 2.0 so can I still program on ISAPI without any additional thingy, cause I already browse the www.borland.com but I can't get anything ISAPI for my 2.0 version and only for 3.0 available.Also rather than just comment please answer my question if you can my friend :) thxx you very much for your attention.
How you retrieve the variable from the form depends on what you specified in the METHOD parameter of the form. If you use "GET", the variables will be encoded on the query string and you can access them as I described before. For example, the following HTML (based on the one you gave) :

<Form Action="/cgi-bin/cgi.exe"
method="get"> Your name:<BR><input type="text" name="name"><p> <input type="submit" value="ok"> </form>

Will produce the following query string, assuming the value in the name field is "ygolan" :


If you use POST instead of GET (<form ... action="post">), reading the values is more complicated, since they are sent in the input stream (stdin) instead of QUERY_STRING. Unless you are sending large (> 1024 bytes) amounts of data, there is no need for you to get into this. However, if you need to do that, just read the data from the stdin - it is in the same format as the query string. The amount of data you should read is specified by the CONTENT_LENGTH environment variable.

Sending the submitted data by mail is a whole different question :-)

I really suggest that you consider using a 3rd party product instead of trying to do it all yourself. There are some pretty good products out there for Delphi 2 and Delphi 3 - I know because I wrote one of them :-)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Wow okie I sought to try your answer ASAP :)But can you tell me how to create simple"HELLO WORLD" like at CGI in ISAPI usesDelphi 2.0 without any additional thingy component ??nice thxxx you answer excellent - AnaKecil -

Library project1;

Uses Classes, SysUtils, Windows, ISAPI;

Function GetExtensionVersion (var pVer : THSE_VERSION_INFO) : BOOL; export; stdcall;
  StrPCopy(pVer.lpszExtensionDesc, 'Hello World Sample DLL');
  result := true;

Function HttpExtensionProc (var pECB : TEXTENSION_CONTROL_BLOCK) : DWORD; export; stdcall;
  HelloMsg : string = 'Hello World';
  Size: dword;
  DataType: dword;
  pECB.ServerSupportFunction( pECB.ConnID,

  Size := Length(HelloMsg);
  pECB.WriteClient( pECB.ConnID, PChar(HelloMsg), Size, 0 );



Thxx so much :) I'll try that one for my first ISAPI app. Anyway could you give me description on your email send program ? so I may think about to buy that component :) also tell me can I pay you via VISA CARD ??okie you always excellent- AnaKecil -

What I've developed is not a email send component. Instead, it's a framework for developing Web applications using Delphi. It's called WebApp, and you download a preview version from ftp://ftp.hyperact.com/pub/beta/wapprvw.zip.

If you need more information, contact me through ygolan@hyperact.com.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.