Link to home
Start Free TrialLog in
Avatar of Brad N
Brad N

asked on

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.

considerations:
* 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.
Avatar of FactorB
FactorB

I've just wrote how to fill in the web pages with javascript here:
https://www.experts-exchange.com/questions/23126491/Login-auto-login-with-TWebBrowser-using-Windows-authentication.html?cid=295

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();

Avatar of Brad N

ASKER

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();');
Avatar of ThievingSix
Wouldn't it be:
WebBrowser1.Navigate('javascript: function five() { document.initialTransaction.cardExpiryMonth.value="' + pchar(Month) + "'; } five();');

Open in new window

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.
ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brad N

ASKER

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.