Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTML form/HTML in smart dialog
#1
Is there a way to submit/read the output of a local html form ("c:\form.html") directly into QM (as individual fields/vars or in an array)?

I've got it working using JScript to write a text file from the form output and getfile to bring it in, but was hoping to avoid this extra step, and the potential for "murphy's law" errors that goes with it...

Thanks!
Steve

(related question to follow in next post...)
#2
How do you do it with JScript?
#3
(sorry for delay, on vacation, very little web access...)

I'm using java to write a cookie containing form data in csv form, and using QM to getfile and parse text/drop down inputs, assign text strings to to radio intergers, reformat date etc.

So...in answer to my question, QM cannot receive/process form data directly?

If not, how about reading the contents of a text field or index value from radio buttons live when focus is moved to next field? or all fields upon submit (fake submit action, read entered values straight from fields)?
#4
Can you show your current code in QM and in web page?
#5
I'll make up a simple form with the script and QM macro example (I don't have access to my actual QM macro or html as I didn't bring along on vacation...). I'll post in a bit...
#6
Sample HTML form in dialog.

Shows:

Creating html document without using a file.
Receiving events fired by html document and elements.
Getting form data.


Attached Files
.qml   HTML dialog.qml (Size: 3.49 KB / Downloads: 564)
#7
Wow...a lot of work, thanks so much -- I'll have to spend some time to follow the complete thread and components. I already see some things that will help out if I keep the below framework.

I took a fairly different approach on this as I mentioned earlier. A "from memory" example is recreated here, went a bit overboard on comments in the macro and the html java script, but maybe it'll help others. The example's pretty bare bones, but you'll get the idea, and possibly give me a gold star for originality? ; )

PS pay no attention to "Fixme"s in the code - just notes to myself so I can search and quickly find things I want to expand upon etc.


read_cookie_mac

Code:
Copy      Help
//set variables
str logon logon_form cookie_dir cookie_text form_data cookie_dir_wildcard cookie_path

//get user logon name
if(rget(logon "Logon User Name" "Software\Microsoft\Windows\CurrentVersion\Explorer"))

//format str "logon_form" for use in filename
    logon_form=logon
    logon_form.lcase
    logon_form.replacerx(" " "_" 1)
    
//format cookie directory and wildcard search string    
    cookie_dir.from("C:\Documents and Settings\" logon "\Cookies\")
    cookie_dir_wildcard.from(cookie_dir logon_form "*local*.*")
    del cookie_dir_wildcard ;;deletes prior cookies created by this process
    
//open html form in dialog
// FIXME --> nicked from QM "diag w/ browser"
// HELP --> How to resume macro upon HTML submit button press??
    str+ site = "c:\formtest\cookie.html"
    str controls = "3"
    str ax3SHD
    if(!ShowDialog("read_cookie_diag" &read_cookie_diag &controls)) ret

//enumerate string match and read file
    lpstr cookie_actualname=dir(cookie_dir_wildcard)
rep
    if(cookie_actualname = 0) break
    cookie_path.from(cookie_dir cookie_actualname)
    cookie_text.getfile(cookie_path)
    cookie_actualname = dir
    form_data=cookie_text
    
// Process form data
form_data.replacerx("%20" " " 1)
out form_data

// FIXME --> add enumerate/parse data next

read_cookie_diag (note, this is QM's "dialog with browser" quickly adapted for this example - it requires "we3_DocumentComplete" which also came in Samples2)

Code:
Copy      Help
\read_cookie_mac
function# hDlg message wParam lParam
if(hDlg) goto messages

Web browser control is defined in SHDocWv type library, which is already declared, so we don't have to declare it again.

BEGIN DIALOG
0 "" 0x10CF0A44 0x100 0 0 277 200 "Submit writes a cookie"
3 ActiveX 0x54000000 0x4 12 20 236 154 "SHDocVw.WebBrowser"
1 Button 0x54030001 0x0 104 4 48 14 "OK"
END DIALOG
DIALOG EDITOR: "" 0x202000B "read_cookie_mac" ""


ret
messages
sel message
    case WM_INITDIALOG
    SHDocVw.WebBrowser we3._getcontrol(id(3 hDlg))
    we3._setevents("we3_DWebBrowserEvents2")
    we3.Navigate(site)
    
    case WM_SIZE
    RECT r; GetClientRect(hDlg &r)
    MoveWindow id(3 hDlg) 0 30 r.right r.bottom-30 1
    
    case WM_COMMAND goto messages2
ret
messages2
sel wParam
    case [4,5,6,7,8]
    err-
    we3._getcontrol(id(3 hDlg))
    sel wParam
        case 4 we3.GoBack
        case 5 we3.GoForward
        case 6 we3.Stop
        case 7 we3.Refresh
        case 8 we3.GoHome
    err+
    
    case IDOK
    case IDCANCEL
ret 1


Zip file contains the above macro and dialogs, plus simple html form and html success message. For this example, be sure to put the folder contained in the zip file in the C:\ root, and of course import the mac and diag files.



Steve


Attached Files
.zip   formtest.zip (Size: 3.23 KB / Downloads: 417)
#8
Test results:
1. The cookie sometimes exists and sometimes not.
2. On Vista does not work because the registry value does not exist.
#9
Just got back...

Thanks for taking the time to test.

RE Vista:
Good call. Have not been able to upgrade because there are no Vista upgrade solutionsfor half of the audio and video h/w & s/w I use professionally.

Is there a similar method to retrieve current logon info in Vista/do I have to worry about all registry calls incorporated in code?

RE Intermittent Cookie: Now that is strange. I have not had a failure to write a cookie in very many tries on three systems (unless of course java is completely turned off, but that wouldn't explain intermittent behavior).

In any case thanks for taking the time in coding and testing -- Ultimately the ability to process an HTML form in QM will be useful to many. Now it's time for me to figure out your example...

Cheers,

Steve
#10
I used GetUserComputer to replace rget when tested on Vista.

More than 50% of times I run the macro I get RT error because the cookie does not exist. On XP and Vista is the same. Works, doesn't, doesn't, doesn't, doesn't, works, doesn't, ....

I created function that monitors $cookies$ folder and displays added/deleted/modified files. When your macro works, the function displays

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

, which means that the file is added and modified.

When it does not work, the function displays

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
2 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

, which means that the file is added, modified, and immediately deleted.
#11
I cannot get it to fail at all: 2 desktops, 1 notebook. Tried different logon accts on the same computer, different rights. 1 desktop and the notebook have virgin QM demo installs and the macro components from the downloaded zip posted earlier. All are XP pro.
--------
You've helped plenty -- I really won't be offended if you don't have time for troubleshooting questions:

You are describing an intermittent or random issue, but for practical purposes, that is impossible (barring faulty RAM, other hardware failings). It must be caused by something, and should be repeatable, wouldn't you expect?

1 . When you say the cookie is
Quote:"immediately deleted"
do you mean:

a. It is literally deleted just after it is written (on clicking SUBMIT) but before hitting OK to close diag and resuming the macro? --> problem in html/java performance.
Test: Open your logon cookie folder, then run macro to just after clicking SUBMIT (but do not hit OK to resume macro). You should see the cookie written: logonname@~~local~~[1].txt

If you hit backspace from cookie_message,html you can go back and forth entering data and writing a new cookie each time you click SUBMIT (the number at the end of cookie filename should alternate between [1] and [2] making it easy to see the change).

If the file already existed in the folder from previous run, you should see it deleted upon start of macro.

b. It is deleted after clicking SUBMIT, displaying the cookie_message,html AND then clicking on OK? --> problem in macro/something unique to your configuration compared to my 3 systems tested.

2. Is it possible that you may have skipped the SUBMIT button and clicked diag OK button on the ones that failed? That would definitely account for it. (I know this whole arrangement in the example is clumsy and should be consolidated into one button, which you've got in your example)

3. The "del cookie_wild..." line near the top of the macro is not really needed, as the cookie is just overwritten anyway each time macro is run past clicking on the SUBMIT button.

4. Are there other local cookies in dir? Any other programs writing local cookies?

I keep thinking of possible causes (like ie permissions, java settings, do not show hidden files etc settings), but it always comes back to your intermittent/unpredictable testing results and none of those could be the culprit...
#12
1. Deleted immediately after Submit (created and immediately deleted). Works well first time, then does not work for about 50 seconds, then works 1 time, and so on.

2. No.

3. Works well if del is removed. Then the output of the file monitor is either

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
2 C:\Documents and Settings\G\Cookies\g@~~local~~[2].txt

or

1 C:\Documents and Settings\G\Cookies\g@~~local~~[2].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[2].txt
2 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

Here 1 means "created", 8 "modified", 2 "deleted". Note that all 3 lines appear immediately after Submit.
#13
Thanks...then it seems to point to a problem with expiry date handling.

Tho I'm still not yet sure why you have issues and my test systems don't, I certainly now have several things to try, and I'll also put in some debug messages into the script.

By leaving the old cookie until the point where a new one is written (because "del wild..." line was removed), forces a new expiry date into the cookie writing. Just a theory right now, and I'm certainly no expert but the varying differences in time when it works/doesn't/works again may have to have to do with how long before the OS takes to get around to removing expired cookies (background services priorty?).


Q1. Is the output of your folder polling function in chronological order? In other words, in your latest test results for each macro run, this happens in order:
  • a new cookie file is created (say " ...[1].txt" ),
    that cookie is modified ( ...[1].txt is populated with data from form/js),
    and then, if exists already, earlier cookie ( ...[2].txt ) expires and is deleted.
So, if you go into your cookies folder and manually delete the local cookie before running the macro again, your f(out) =

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

Q2. Is the function called at a certain point in my mac code, or is launched separately and truly polling any changes in the folder continuously?

Q3. Can you share the code (be very useful here, and in other apps...)?

Thanks again.
#14
A1. I'm sure.

If the cookie exists before the macro runs, the macro deletes it:

2 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

Then, when I click Submit, the cookie is created and immediately deleted:

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
2 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

If i manually delete the cookie file before I run the macro, on Submit it is created/deleted anyway.

After 30-60 seconds works well again, one time:

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt


A2. The file monitoring function is not called from code. It simply has file trigger.

A3.

Function AnyName
Trigger:
$f 0x4F "$cookies$"
Code:
Copy      Help
function event $name [$newname]
;event: 1 added, 2 removed, 4 renamed, 8 modified
out "%i %s" event name

QM file triggers monitor all file system changes in real time, without polling.
#15
A1. I'm sure.

If the cookie exists before the macro runs, the macro deletes it:

2 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

Then, when I click Submit, the cookie is created and immediately deleted:

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
2 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

If i manually delete the cookie file before I run the macro, on Submit it is created/deleted anyway.

After 30-60 seconds works well again, one time:

1 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt
8 C:\Documents and Settings\G\Cookies\g@~~local~~[1].txt

Never works after I press Backspace and click Submit. I have to close the dialog and wait 30-60 s.

A2. The file monitoring function is not called from code. It simply has file trigger.

A3.

Function AnyName
Trigger:
$f 0x4F "$cookies$"
Code:
Copy      Help
function event $name [$newname]
;event: 1 added, 2 removed, 4 renamed, 8 modified
out "%i %s" event name

QM file triggers monitor all file system changes in real time, without polling.
#16
Between yours vs. my function comparison and the fact that backspace/resubmit won't work for a period of time (whereas mine is immediate) narrows it down a good bit.

With del line active, and a cookie in folder, I get correct behavior every time:

Upon macro del line:
  • 2 C:\Documents and Settings\Steve Murphy\Cookies\steve_murphy@~~local~~[1].txt

Upon Submit:
  • 1 C:\Documents and Settings\Steve Murphy\Cookies\steve_murphy@~~local~~[1].txt
    8 C:\Documents and Settings\Steve Murphy\Cookies\steve_murphy@~~local~~[1].txt

Repeat results same.

----so here's the interesting bit, please correct if not true to your results----------

CASE Del Line Active. The del line has nothing to delete because in every prior run it is deleted automatically and immediately. As a result, you do not get a output from file monitor at the point of macro del line.

The phantom behavior can be observed/hypothesized as:

Upon first run or following a macro run with a short and perhaps varying time-out period of a minute-ish, the cookie is deleted immediately after creation, but manages to live long enough for you to hit OK so the macro can get the data out.

If you leave the browser open and rock back and forth between message and submit html pages, it NEVER writes a new cookie, even if you change the data in the text fields, and even if you wait a minute or more between submittals (in other words, it appears the browser session MUST be closed before it will ever rewrite cookie [vs mine, which as expected writes new cookie every time, without fail, without delay]).

CASE Del Line Inactive. This results in correct behavior every time (if cookie already exists at runtime) because the cookie that gets phantom deleted upon submittal is actually the previous run's cookie as we saw in your earlier post: [1], [1], [2] or [2], [2], [1]

----
Symptoms seem to point to cookie being treated by browser/ie settings as session-only and probably page-only life span instead of using the actual expiry date, which is what my systems are doing. The wait period is probably the opposite of what it appears - post waiting time, the (incorrectly interpreted) session cookie deletion routine is slow on the draw, remains ready to destroy for about a minute, and is forced out of cache and back into semi retirement by OS) .

Until I can figure out why cookie is being degraded on your system (and possibly others), the work-around/safeguard method is to remove delete line, and even set.file a cookie at beginning of macro if one doesn't exist already to kickstart the [1] [2] alternating.
#17
Quote:backspace/resubmit won't work for a period of time (whereas mine is immediate)

backspace/resubmit works, but the cookie is created/deleted on every Submit, regardless of how long I wait. But if i close the dialog and wait 1 minute, then on Submit the cookie is created and not deleted. Next time del deletes it, and on Submit it is created/deleted again.

Without del, if new cookie is [1], then after its creation is deleted cookie [2], and vice versa. With del, Windows creates and deletes cookie [1]. Maybe Windows thinks it has to delete old cookie, but does not check whether it is [2] or some other number, and just deletes oldest existing cookie. Since there are no other cookies (only new cookie [1]), it deletes [1].
#18
I think Windows does not like deleting cookie files. Try to delete it in javascript using negative expiration time. I also know API functions to set cookies but they don't allow to set expiration time or delete.
#19
Quote:I think Windows does not like deleting cookie files
This is true...but the usual result is recreating the deleted cookie from mirror copy, not unilaterally choosing to delete a legitimately places and dated cookie.

Quote:Without del, if new cookie is [1], then after its creation is deleted cookie [2], and vice versa.
This is reasonable behavior when the same domain is writing a new cookie. But your comment raises a great point. Windows doesn't like patrolling cookies at all. They are there for the site to use/maintain etc. If one expires, that is more meaningful to the site than to windows.
--> after I get back from out of town this weekend, I'm gonna try adding some cookie checking code (if exist etc) to the script on the form, which may indeed be the key.

Still doesn't explain the difference in behavior between yours and my systems. Would very much like someone else to try and see what happens...

Cheers,

Steve
#20
A little help please;

I have spent the last week learning HTML, JavaScript and more but I just cannot pull this rabbit out of the hat.

I am trying to change the HD_sample_get_form_data to a 4 choice radio. I have tried things like changing str s2=ch.getAttribute("checked" 0) –to- str s2=ch.getAttribute("value" 2) but the best I can get is 0,-1 or Yes and I believe that this means checked or unchecked . Is there a way to change this into a 4 choice radio?

Example:

Macro
Code:
Copy      Help
;1) Do you like cats?<br>
;<input type="radio" name="Questioner1" value="Yes"> Yes<br>
;<input type="radio" name="Questioner1" value="No"> No<br>
;<input type="radio" name="Questioner1" value="Cats are ok but Dogs are better"> Cats are ok but Dogs are better<br>
;<input type="radio" name="Questioner1" value="None of the above"> None of the above<p>
#21
i would add id attribute
Code:
Copy      Help
<form name="f" method="post" action="">
;1) Do you like cats?<br>
;<input type="radio" name="Questioner1" id="r1" value="Yes"> Yes<br>
;<input type="radio" name="Questioner1" id="r2" value="No"> No<br>
;<input type="radio" name="Questioner1" id="r3" value="Cats are ok but Dogs are better"> Cats are ok but Dogs are better<br>
;<input type="radio" name="Questioner1" id="r4" value="None of the above"> None of the above<p>
</form>

and then in
Function HD_sample_get_form_data
Code:
Copy      Help
MSHTML.HTMLInputElement ch
str r1 r2 r3 r4
ch=+doc.getElementById("r1")
r1=ch.getAttribute("checked" 0)
ch=+doc.getElementById("r2")
r2=ch.getAttribute("checked" 0)
;...

and then if r1=-1 ... else if r2=-1 ... and so on
#22
Thank you

That works great.
#23
I have over 100 questions and I am trying to make some sort of function or array to total all my questions and give out information bast on the way the questions where answered such as you are really a cat lover but you like dogs too. I just can not seam to make this work. Can you please give an example of the best way to do this?


Attached Files
.qml   Questioner 3.qml (Size: 46.35 KB / Downloads: 344)
#24
Any word on this error?

Error (RT) in "HTML_dialog_proc /478"oHTML_dialog_proc: invalid interface pointer. Use _create or other function to create or get object

for:
doc.open("text/html")
#25
Dou you have web browser control with id 3 in the dialog?
3 ActiveX 0x54030000 0x0 0 0 356 178 "SHDocVw.WebBrowser"
#26
Yes I have:
" 3 ActiveX 0x54030000 0x0 0 0 356 178 "SHDocVw.WebBrowser""

I downloaded the attached example you provided...it won't work.

None of the doc. things work. If I disable one...then next errors and so forth.

I do get the list when I type doc.

Do you think I might need to reinstall QM?
#27
Function HTML_dialog_sample
Code:
Copy      Help
out

str- t_form_data ;;on OK will be populated with form data

str controls = "3"
str ax3SHD
ax3SHD="" ;;about:blank
if(!ShowDialog("HTML_dialog_proc" &HTML_dialog_proc &controls)) ret

out t_form_data

Is it the main function?
The error could be if you removed ax3SHD="". Then there is no HTML document.
#28
That's what I have...

Function HTML_dialog_sample
Code:
Copy      Help
out

str- t_form_data ;;on OK will be populated with form data

str controls = "3"
str ax3SHD
ax3SHD="" ;;about:blank
if(!ShowDialog("HTML_dialog_proc" &HTML_dialog_proc &controls)) ret

out t_form_data

I haven't changed anything from your example...
#29
What is your QM version and Internet Explorer version?
#30
do I have to do anything to prepare to run the macro? I just downloaded and ran it...nothing else.

Did I just miss something?


Forum Jump:


Users browsing this thread: 1 Guest(s)