Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now