How to automatically fill fields in a web page's form (when loaded in a webview)

1,766 views
Skip to first unread message

Joel R. Putnam

unread,
Nov 15, 2016, 10:49:29 PM11/15/16
to MIT App Inventor Forum
Hi there, I'm taking a crack at my first app. One paper, it's pretty simple, and I've got most of the interface and basic logic figured out, but I'm stuck on one key step that might require an extension of some kind.

My app is pretty simple, it's for making it easy to enter the ticket lottery of a Broadway show. Normally you have to go to a webpage, click a link, and a form is opened in an iframe prompting you for your name, date of birth, etc. I'd like to have an app that stores my name, etc in TinyDB, and then opens the page in a webview. Once it loads the form, I want the fields to automatically be populated by the appropriate entries in TinyDB. If this is confusing, there's a free iOS app that does almost exactly this called Ham (https://itunes.apple.com/us/app/ham-lottery-app/id1088026752?mt=8)

Now, I can store the data easily in TinyDB through a settings screen that prompts for the various values. And I can see the class and IDs for each input field in the web page. But I don't see any obvious way to tell the app to put a TinyDB value into the corresponding an html input element when the iframe loads (or for that matter to get it to notice that the iframe has loaded). Any ideas how to accomplish this?

Thank you!

Taifun

unread,
Nov 16, 2016, 8:35:29 AM11/16/16
to mitappinv...@googlegroups.com
How to automatically fill fields in a web page's form (when loaded in a webview)
unfortunately that's not possible

but probably you can create your own screen using App Inventor components and use the web component to send the data, as it is done in this example https://puravidaapps.com/spreadsheet.php

Taifun


Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Joel R. Putnam

unread,
Nov 16, 2016, 11:11:17 AM11/16/16
to MIT App Inventor Forum
Hi Taifun, thanks for the quick answer. One question about the approach you suggest:

The form I'd like to submit data to includes a Google reCAPTCHA element. The iOS app I reference fills out all the other fields automatically, then has the user handle the CAPTCHA manually. Do you see a way for the user to handle CAPTCHA using the method you're suggesting?
Message has been deleted

Taifun

unread,
Nov 16, 2016, 12:36:43 PM11/16/16
to MIT App Inventor Forum
to prefill some fields on a webpage using the webviewer probably might be possible for older devices (API < 19), see also http://stackoverflow.com/a/13346730/1545993 and http://stackoverflow.com/a/32115462/1545993

this is what the GoToUrl method is doing (copied from the sources)

  /**
   *  Load the given URL
   */
  @SimpleFunction(
      description = "Load the page at the given URL.")
  public void GoToUrl(String url) {
    webview.loadUrl(url);
  }


Taifun

Taifun

unread,
Nov 16, 2016, 3:06:29 PM11/16/16
to MIT App Inventor Forum
I now found a solution, which runs fine on Android 7...
Enjoy!

Taifun

Joel R. Putnam

unread,
Nov 16, 2016, 11:06:07 PM11/16/16
to MIT App Inventor Forum
Awesome, thank you so much for not only considering the response, but creating a page dedicated to a detailed answer! This is above and beyond. I will take a crack at this right away.

Joel R. Putnam

unread,
Nov 17, 2016, 2:11:56 PM11/17/16
to MIT App Inventor Forum
It works great! Thank you again so much! There's only one snag I've run into and it's quite minor. I've figured out how to use this to fill in text fields and to select values for drop-down menus. There's just one checkbox I can't figure out how to automatically check (not the recaptcha, just a normal <input type="checkbox">). I'll look around and post if I find a solution, but does anyone else have any ideas?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages