Board index » delphi » Need help in creating client/server web forms with Delphi

Need help in creating client/server web forms with Delphi

I need to create a database of names and emails, whereby the user inputs his/her
name and email into an activex web form and these details are stored in the
database. A confirmation message is then sent back to the user's web browser
stating that they are now in the database.
If however they are already in the database a result is returned to the user
stating this fact.
I need the activex form to send the name and email to the .exe file, this would
then check to see if the details are in the database and then return the result
back to the web page.
I know how to create the activex forms but I don't know how to link them with a
database which sits on a server. I think I need to use the TNMHTTP component, as
the transfer of data will be over the internet but I am not sure how to use
this?

Any ideas on getting started?
Dani.

 

Re:Need help in creating client/server web forms with Delphi


You do not need ActiveX for this...

You only need to create an HTML file and a small Delphi Web Server App.
(This is all ASSUMING you are using Delphi 4 or 5 and either ISAPI or NSAPI)

The HTML file should use the a "FORM" in it like so:

<FORM ACTION="/Scripts/OurWebServer.EXEorDLL/SaveData" METHOD="POST">
Name: <INPUT TYPE="TEXT" NAME="USERNAME" SIZE="30" MAXLENGTH="30"><BR>
E-Mail Address:<INPUT TYPE="TEXT" NAME="EMAIL" SIZE="100"
MAXLENGTH="255"><BR>
<INPUT TYPE="SUBMIT" VALUE="Save" NAME="Save">
</FORM>

Then inDelphi FILE,  NEW, Web Server Application, (for Testing select the
"CGI Stand-alone executable" option)
This will give you a 'WebModule" - Like a Datamodule but has some extras...
Like ACTIONS
Add a New Action to the WebModule - is not that important for now but the
PATHINFO is, this is the name
of the action from the web server (IIS or NIIS) so call it "SaveData".  (See
above, Form Action Parameter)
Now use the new actions, ONACTION event like so:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
     Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  UserName: String;
  EMail: String;
  qryLocal: TQuery;
begin
  // Get the Params from the Web Server
  UserName := Request.QueryFields.Values['USERNAME'];
  EMail := Request.QueryFields.Values['EMAIL'];
  try
    // Build a Query on the Fly
    qryLocal := TQuery.Create(Self);
    qryLocal.DatabaseName := 'SomeAliasOrDatabaseComponent';
    qryLocal.SQL.Clear;
    // Build the Search Query - Look for Same Name and EMail
    qryLocal.SQL.Add( 'Select * From SomeTable' );
    qryLocal.SQL.Add( 'Where UserNameField = ' + QuotedStr(UserName) );
    qryLocal.SQL.Add( 'And EMailField = ' + QuotedStr(EMail) );
    qryLocal.Open;
    // Were there any records?
    if qryLocal.IsEmpty then begin
      qryLocal.Close;
      // Add the User
      qryLocal.SQL.Clear;
      qryLocal.SQL.Add( 'Insert Into SomeTable Values(' );
      qryLocal.SQL.Add( QuotedStr(UserName) + ',' );
      qryLocal.SQL.Add( QuotedStr(EMail)    + ')' );
      qryLocal.ExecSQL;
      // Say Thank You
      Response.Content := '<HTML><BODY>Thank you for adding yourself to our
Database.</BODY></HTML>';
      end
    else
      // Sorry you already Exist
      Response.Content := '<HTML><BODY>Sorry ' + UserName + ' is already in
our Database.</BODY></HTML>';
  except
    // Error!
    Response.Content := '<HTML><BODY>Sorry there was a
problem!!</BODY></HTML>';
  end;
  // Close and Free the Query
  qryLocal.Close;
  qryLocal.Free;
end;

That is a simple as it gets, if you have any qestions E-Mail me.

--
Thomas Chamberlain, tcham...@3x.com
AS/400 & Delphi Consultant
3X Corporation
Web and Systems Integrators
Worthington, Ohio  USA
www.3x.com

Quote
<DaniellaJac...@SPAMBLOCKHotmail.com> wrote in message

news:8mcj6i$24fc@drn.newsguy.com...
Quote
> I need to create a database of names and emails, whereby the user inputs
his/her
> name and email into an activex web form and these details are stored in
the
> database. A confirmation message is then sent back to the user's web
browser
> stating that they are now in the database.
> If however they are already in the database a result is returned to the
user
> stating this fact.
> I need the activex form to send the name and email to the .exe file, this
would
> then check to see if the details are in the database and then return the
result
> back to the web page.
> I know how to create the activex forms but I don't know how to link them
with a
> database which sits on a server. I think I need to use the TNMHTTP
component, as
> the transfer of data will be over the internet but I am not sure how to
use
> this?

> Any ideas on getting started?
> Dani.

Other Threads