Filling out online forms
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 2
- Joined: Sun Nov 20, 2011 10:36 am
Filling out online forms
Hi Guys,
Quite new to Livecode, but what a great language so far.
Im wanting to know if the following is possible and how it could be done.
Im wanting to fill out an online form and hit the submit button, then grab some information out of the page source of the returned page.
Ive seen some posts on creating a speacial URL and sending that off, but this form doesnt use a url like this...
I would usually use something like iMacros to control this section jumping to the first field entering data, tab to the next field etc then have the macro hit the submit button.
The form im wanting to populate has 2 fields, url and keyword. I have this info stored in variables. so it would either need to launch url then send a tab key several times, paste the url variable hit tab again paste keyword variable tab again and hit enter (this is how i would write the macro,,, can you do the same thing with livecode???)
Any pointers or suggestions would be greatly appreciated.
Loving livecode so far.. id like to keep it that way.
Thanks in advance
Look forward to talking to you.
Regards
OldeEnglish
Quite new to Livecode, but what a great language so far.
Im wanting to know if the following is possible and how it could be done.
Im wanting to fill out an online form and hit the submit button, then grab some information out of the page source of the returned page.
Ive seen some posts on creating a speacial URL and sending that off, but this form doesnt use a url like this...
I would usually use something like iMacros to control this section jumping to the first field entering data, tab to the next field etc then have the macro hit the submit button.
The form im wanting to populate has 2 fields, url and keyword. I have this info stored in variables. so it would either need to launch url then send a tab key several times, paste the url variable hit tab again paste keyword variable tab again and hit enter (this is how i would write the macro,,, can you do the same thing with livecode???)
Any pointers or suggestions would be greatly appreciated.
Loving livecode so far.. id like to keep it that way.
Thanks in advance
Look forward to talking to you.
Regards
OldeEnglish
Re: Filling out online forms
There's no easy way to control other apps from LiveCode or from any other program, actually. If you're on a Mac you could possibly use AppleScript, but that wouldn't be much easier in the long run.
One thing you could do is use a browser control in the stack to load the form URL. Then you can get the html text of the browser, parse it to put your variable values into the correct places, and reload the revised html back into the browser control. It's hard to parse the HTML this way though unless you know exactly what you're looking for in the text.
Another way, which would probably be the first thing I'd try, would be to store the html of the web form in a custom property or a variable. Put placeholders into the locations where your variable values should go, and when it is time to use the form, replace the placeholders with the values you've stored. Then just post or send the html back to the server. If you do it this way, the whole process would be invisible to the user -- no form, no submit button, it would all take place in the script. I use this method frequently. It is much easier to parse html when you are looking for a specific placeholder string like "*****URL*****". You just need to use the "replace" command to swap in your own value.
One thing you could do is use a browser control in the stack to load the form URL. Then you can get the html text of the browser, parse it to put your variable values into the correct places, and reload the revised html back into the browser control. It's hard to parse the HTML this way though unless you know exactly what you're looking for in the text.
Another way, which would probably be the first thing I'd try, would be to store the html of the web form in a custom property or a variable. Put placeholders into the locations where your variable values should go, and when it is time to use the form, replace the placeholders with the values you've stored. Then just post or send the html back to the server. If you do it this way, the whole process would be invisible to the user -- no form, no submit button, it would all take place in the script. I use this method frequently. It is much easier to parse html when you are looking for a specific placeholder string like "*****URL*****". You just need to use the "replace" command to swap in your own value.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 2
- Joined: Sun Nov 20, 2011 10:36 am
Re: Filling out online forms
Hey Jacque,
Thanks for getting back to me,
I like your thoughts, can you tell me how you would work out the address to post back to, (do you just post it back to the URL?, or to the destination of the "submit" button?)
I was also wondering if livecode could instead of posting directly, trigger an exe macro?
I could have the exe macro set up on the desktop with all the user actions for controlling firefox etc the macro could end, by clicking something within the livecode application, letting livecode takeover and finish the task with the data?
Do you think something like this would work?
So main question, can you trigger an exe from livecode?
UPDATE!!!
Seems you can... quite easy really haha
launch "app.exe"
Did i mention im new around here.!
Thanks for getting back to me,
I like your thoughts, can you tell me how you would work out the address to post back to, (do you just post it back to the URL?, or to the destination of the "submit" button?)
I was also wondering if livecode could instead of posting directly, trigger an exe macro?
I could have the exe macro set up on the desktop with all the user actions for controlling firefox etc the macro could end, by clicking something within the livecode application, letting livecode takeover and finish the task with the data?
Do you think something like this would work?
So main question, can you trigger an exe from livecode?
UPDATE!!!
Seems you can... quite easy really haha
launch "app.exe"
Did i mention im new around here.!

Re: Filling out online forms
Glad you figured it out. The launch command is the right way to do it. Since you're just starting, that's probably the easiest way if the form is only for your own use.
If you want to post back to the URL, you can use the "post" command if the form uses POST. If it uses GET then you can do it with "put". You'd need to look at the form HTML and see where the submit button sends data and which method it uses. Then after you've revised the raw HTML, you'd put or post it to that URL. But probably for now your solution is okay.
If you want to post back to the URL, you can use the "post" command if the form uses POST. If it uses GET then you can do it with "put". You'd need to look at the form HTML and see where the submit button sends data and which method it uses. Then after you've revised the raw HTML, you'd put or post it to that URL. But probably for now your solution is okay.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Filling out online forms
Hi @Jacque, could you please help me to use your suggested method to Submit the following form?
This is the HTML of the form I want to fill/submit
I want my LC script to be able to fill in the file name and then submit the form, should be doable with your method but I wasn't able to figure out how.
Many thanks in advance for your help
This is the HTML of the form I want to fill/submit
Which looks like this<!doctype html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<h1>File Upload</h1>
<form method="POST" action="" enctype="multipart/form-data">
<p><input type="file" name="file"></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
I want my LC script to be able to fill in the file name and then submit the form, should be doable with your method but I wasn't able to figure out how.
Many thanks in advance for your help
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: Filling out online forms
The first question is whether you want the HTML displayed in a browser, or whether you just want to send the file off invisibly in the background. If you don't want any user interaction, it seems unnecessary to provide an HTML form. In either case, the form action needs to provide a URL where the submission should be sent. (You may have just left that out for privacy reasons.)
If you do want to give the user an interface to work with, then they should click the Submit button. But you can change the file name by adjusting the HTML template. You can keep the template in a custom property, or load it in from a file on disk. The template could look like this:
The file name is represented by an easily-found custom string "**file**". You'd use the replace command to alter the template:
If you're comfortable with the merge command, it does the same thing but is more compact to use if there are several variables in the HTML that need to be replaced.
If instead you just want to send the file off with a POST command, you don't need HTML at all. I've never posted an entire file, but I'm guessing it might be as simple as:
where the updated/edited version of the template is stored on disk. If the POST is successful you can delete the temp file if you want. The variable tResult will tell you if it succeeds.
If you do want to give the user an interface to work with, then they should click the Submit button. But you can change the file name by adjusting the HTML template. You can keep the template in a custom property, or load it in from a file on disk. The template could look like this:
Code: Select all
<!doctype html>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<h1>File Upload</h1>
<form method="POST" action="" enctype="multipart/form-data">
<p><input type="file" name="**file**"></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
Code: Select all
replace "**file**" with "name of file" in tTemplate -- tTemplate is the HTML content above
If instead you just want to send the file off with a POST command, you don't need HTML at all. I've never posted an entire file, but I'm guessing it might be as simple as:
Code: Select all
post url ("binfile:" & tFilePath) to "https://whatever.com"
put the result into tResult
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: Filling out online forms
Thanks Jacque, I'll try the second approach which fit best my goal and will report back the result
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question