Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-04-13
3
Medium Priority
?
232 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 80 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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