Use delphi to automatically fill in a form

Background: I receive credit card payments by email.  The email is encrypted when it arrives.  i need to unecrypt it and paste the card number, expiry, reference number, etc into my secure payment gateway provided by the bank.

Objective: automatically parse an email and paste the contents into a web form. I want to automate the cut and paste process of this step.

Problem: I am not sure how to paste/insert the information into the relevant fields of the banks webform.

* Parsing the unencrypted email i can do (cut and paste the entire email into a delphi memo which will process it based on constants in the text.  Data will then be assigned to corresponding variables in the EXE ready for further action)
* The names of the fields in the bank form do not change
* the url to the bank form does not change, although it is behind a master login system. (it would be better if the application could search through all open urls, and select one based on regular expressions - for example select the web page that starts with 'https://migs'
* web form names are orderNumber, amount,  avsData.cardholderName,  cleartextCardNumber,  cardExpiryMonth,  cardExpiryYear, csc,  ticketNumber

The Question:
How do i take the parsed information and automatically insert the information into the right spots on the banks web page.

Pretty much what the commerical software roboform  (password manager) does, the key difference is:
* I only have 1 web page i am interested in filling.
* The inserted data changes each time as it based on card information.

Any help appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I've just wrote how to fill in the web pages with javascript here:

Open the web page that you need to give command to, read the source and find and change form with form name and input with the name of input field, now just paste the changed code in the address bar and press enter.

javascript: function one() { document.form.input.value="Insert This Text In Input." ; } one();
javascript: function two() { document.form.submit() ; } two();

delphinewbieAuthor Commented:
Not quite what i had in mind but it achieves the result required.

The script works when i hardcode the values to be entered in "quotations", but how to I pass my variables to the java  script:

As an example i have tried the 'raw' variable as well as pchar(variable).  All the variables are defined as text.  Get an error when running the script with the variables instead of the 'fixed text'

Example below:
WebBrowser1.Navigate('javascript: function five() { document.initialTransaction.cardExpiryMonth.value=pchar(Month); } five();');
Dagan HooverDeveloperCommented:
Wouldn't it be:
WebBrowser1.Navigate('javascript: function five() { document.initialTransaction.cardExpiryMonth.value="' + pchar(Month) + "'; } five();');

Open in new window

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Dagan HooverDeveloperCommented:
WebBrowser1.Navigate('javascript: function five() { document.initialTransaction.cardExpiryMonth.value="' + pchar(Month) + '"; } five();');

Mixed up the quotes at the end.
You have not shared what you had on mind, but always keep it simple, simpler it is gives less chances for mistakes. You can not pass delphi variable directly into javascript, you should include its value in the string just like ThievingSix wrote. His second code should work (double quote, single quote, plus sign, variable value as string, plus sign, single quote, double quote). If you want some other approach, tell us.
Mark BradyPrincipal Data EngineerCommented:
I assume you have several fields to fill out on a TWebbrowser with the credit info so if you do something like this......

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

Let's assume you have 3 items that need to be filled out.  You obviously know how to extract this data from your emails correct ?

Using string variables inside your procedure you can fill out the forms.

// To call the function add this code to your procedure  ......

YourFieldNamne, Value : String;
YourFieldName := ();    // Inside the brackets put your first fieldname variable.....
Value := ();   // Inside the brackets put your first Value variable.....

// Inside the brackets put your first fieldname variable.....

// Now to call the function use the following code.....

if FillForm(WebBrowser1, 'YourFieldName', 'Value') = False then
Showmessage ('Your Form could not be Filled !')

// As you have multiple forms to fill out or fields just modify the code to suit.  If you have any problems let me know ok.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
delphinewbieAuthor Commented:
Perfect Solution.  I was thinking originally to try fill the forms in an internet explorer window, but this is just as good as I get the same result.   The Java solution was not working, even with the quotes.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.