Solved

# CGI Reading the Info from a POST Action

Posted on 1998-03-26
Medium Priority
167 Views
I have created a CGI class but I need to decode the fields sent to me when I use a POST action. How do I do that ???

This one is urgent so I pay a lot for it.
0
Question by:malaland
• 4

LVL 4

Accepted Solution

itamar earned 300 total points
ID: 1360944
Hi malaland,

Here are some functions to accomplish the task. Tey were extracted from FPiettes CGI sample.

All you have to use is the GetValue procedure, the others are auxiliar. An example goes below.

The functions:

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;

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;

The example:

procedure TForm1.Button1Click(Sender: TObject);
var token: string;
Source: string;
begin
Source := 'pg=q&what=web&kl=XX&field=cora%E7%E3o&search.x=41
GetValue(Source, 'field=', token);
Edit1.Text := token;
GetValue(Source, 'what=', token);
Edit2.Text := token;
end;

// Edit1 will show the result: "coração" (heart in portuguese).
// and Edit2 will show the result: "web", and so on...

I believe it will be usefull. If you need to elaborate it (and have time) I could help you.

IHTH,

Itamar

P.S.: Any doubts, place a comment before rejecting the answer.
0

LVL 4

Expert Comment

ID: 1360945
Hi malaland,

I put this coment just to fire a msg for you, as you said it was urgent.

Bye,
Itamar
0

LVL 4

Expert Comment

ID: 1360946
Hi !

Anybody there ????
0

Author Comment

ID: 1360947
You did not quite get the answer but I found out by myself. To read the POST information comming into my CGI application, I needed to read the standard IN. Thanks for you help.
0

LVL 4

Expert Comment

ID: 1360948

First of all, your question mentions "decode the fields sent to me" ! To decode something I guess you already know how to get the thing to be decoded !!!!

I sugest you to make the questions more clear, this way you'll save everybody's time and will not frustate someone with such a low grade :(((((
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.