Solved

Get data from (html form) to my cgi app.

Posted on 1998-04-13
3
223 Views
Last Modified: 2010-04-06
I'm new in cgi and i want to know how can i get data send from a html form to my cgi
0
Comment
Question by:ahmosa
3 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1361480
You need a CGI tutorial, unless you are able to tighten a bit and just didn't tell.
0
 
LVL 4

Accepted Solution

by:
itamar earned 20 total points
ID: 1361481
Hi ahmosa,

here is a complete working code from FPiette's. If you have problems with Cut & Paste, I can send it by e-mail. Send your e-mail to itamar@facil.com.
{$APPTYPE CONSOLE}
program cgisimda;

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Author:     François PIETTE
Email:      francois.piette@ping.be  http://www.rtfm.be/fpiette
          2:293/2202@fidonet.org BBS: +32-4-365.13.95
Copyright:  You can use this software freely, at your own risks
Creation:   December 1996
Object:     CgiSimpleData implement a (very basic) CGI program accessing
            data passed by the Web server
            Tested with Microsoft IIS and Microsoft Personal Web Server
Updates:


 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
uses
    Windows, SysUtils;

function isxdigit(Ch: char) : Boolean; forward;
function xdigit(Ch: char) : Integer; forward;
function htoin(value: PChar; len: Integer) : Integer; forward;
function GetValue(Msg: String; Name: String; var Val: String): Boolean; forward;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure Cgi;
var
    Len               : Integer;
    Count             : Integer;
    Buffer            : array [0..2047] of char;
    NumberOfBytesRead : Integer;
    Nom               : String;
begin
    WriteLn('Content-type: text/html');
    WriteLn;
    WriteLn('<HTML>');
    WriteLn('<HEAD>');
    WriteLn('<TITLE>Hello !</TITLE>');
    WriteLn('</HEAD>');
    WriteLn('<BODY>');
    WriteLn('<P>');

    Len := GetEnvironmentVariable('CONTENT_LENGTH', Buffer, SizeOf(Buffer));
    Buffer[Len] := #0;

    if Len = 0 then
        Count := 0
    else
        Count := StrToInt(Buffer);

    if Count = 0 then
        NumberOfBytesRead := 0
    else
        ReadFile(GetStdHandle(STD_INPUT_HANDLE),
                 Buffer, Count, NumberOfBytesRead, nil);
    Buffer[NumberOfBytesRead] := #0;

    GetValue(Buffer, 'Nom=', Nom);

    WriteLn('<H1>Hello ', Nom, ' !</H1><br><br>');

    WriteLn('CONTENT_LENGTH=', Count, '<br>');
    WriteLn('NumberOfBytesRead=', NumberOfBytesRead, '<br>');
    writeln('Content: ', '''', Buffer, '''<br>');

    WriteLn('</P>');
    WriteLn('</BODY>');
    WriteLn('</HTML>');
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function isxdigit(Ch : char) : Boolean;
begin
    Result := (ch in ['0'..'9']) or (ch in ['a'..'z']) or (ch in ['A'..'Z']);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function xdigit(Ch : char) : Integer;
begin
    if ch in ['0'..'9'] then
        Result := ord(Ch) - ord('0')
    else
        Result := (ord(Ch) and 15) + 9;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function htoin(value : PChar; len : Integer) : Integer;
var
    i : Integer;
begin
    Result := 0;
    i      := 0;
    while (i < len) and (Value[i] = ' ') do
        i := i + 1;
    while (i < len) and (isxDigit(Value[i])) do begin
        Result := Result * 16 + xdigit(Value[i]);
        i := i + 1;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function GetValue(Msg: String; Name: String; var Val: String): Boolean;
var
    I       : Integer;
    NameLen : Integer;
    Ch      : Char;
begin
    Val     := '';
    NameLen := Length(Name);

    I := Pos(Name, Msg);
    if I = 0 then begin
        Result := FALSE;
        Exit;
    end;

    I := I + NameLen;
    while (Msg[I] <> #0) and (Msg[I] <> '&') do begin
        Ch := Msg[I];
        if Ch = '%' then begin
            Ch := chr(htoin(@Msg[I + 1], 2));
            I  := I + 2;
        end
        else if Ch = '+' then
            Ch := ' ';

        Val := Val + Ch;
        Inc(I);
    end;
    Result := TRUE;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
begin
    Cgi;
end.

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

IHTH,
Itamar
0
 

Author Comment

by:ahmosa
ID: 1361482
Thank you itamar
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question