Solved

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

Posted on 1998-04-13
3
225 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
How to convert memory stream to PDF file 6 104
DBGrid or StringGrid ? 6 103
How to Get Images From Server to Client using App Tethering 1 25
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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