Solved

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

Posted on 1998-04-13
3
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

617 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