Advertisement

02.28.2008 at 10:53AM PST, ID: 23201411
[x]
Attachment Details

Fill form  HTML web page form fields and submit DELPHI

Asked by selas in Delphi Programming Language, Delphi Programming, Delphi Components

Tags: Delphi

Hello.
i am using T WebBrowser and want to fill HTML web form fields and submit form. My code sample is:

function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Showmessage('nera formu');
    Exit;
  end;
  //count forms on document
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
          FormItem.Item(j).Value := Value;
          Result := True;
        end;
      except
        ShowMessage('ajajai klaida');
        Exit;
      end;
    end;
  end;
end;


// Step Number 1
// loading page

procedure TfrmMain.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate(edDest.Text);
end;

// Step Number 2
// filling and submiting form
procedure TfrmMain.Button2Click(Sender: TObject);
const
  fields: array[1..11] of string=('title', 'location', 'description', 'age', 'contact_email', 'first_name', 'last_name', 'user_phone', 'user_email', 'password', 'policy_accepted');
  values: array[1..11] of string=('title geras cia yra',
                                  'lokacija',
                                   'Deskripcija', '18', 'exga@yahoo.com', 'Ixmamud', 'ehmeda', '348665954', 'Car@yahoo.com', '123456789', '1');
var
  theForm: IHTMLFormElement;
    document: IHTMLDocument2;
        i: integer;
begin

// fill form fields
  for i:=1 to Length(fields)  do
  begin
    if FillForm(WebBrowser1, fields[i], values[i]) = False then
    Showmessage ('Your Form could not be Filled !')
  end;
// submit form
  document := WebBrowser1.Document as IHTMLDocument2;
  theForm := GetFormByNumber(document, 0);
  TheForm.submit;
end;

end;


after submiting form i got page erorr: "This posting category does not support images.".  But i did not post image so i don't know where error exists. Help please.Start Free Trial
[+][-]02.28.2008 at 11:32AM PST, ID: 21007217

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 11:40AM PST, ID: 21007294

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 12:14PM PST, ID: 21007577

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.29.2008 at 12:30PM PST, ID: 21017237

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.29.2008 at 12:36PM PST, ID: 21017290

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.01.2008 at 03:24AM PST, ID: 21021142

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.01.2008 at 03:45AM PST, ID: 21021179

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.02.2008 at 12:57AM PST, ID: 21025405

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.02.2008 at 02:18AM PST, ID: 21025534

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Delphi Programming Language, Delphi Programming, Delphi Components
Tags: Delphi
Sign Up Now!
Solution Provided By: ciuly
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628