In order to collect data from an HTML form displayed in a remote browser, a page containing HTML content needs to be registered with vizhtml's local HTTP server. A form submission event will get triggered once a form is submitted and data can be collected using a task or callback function.
The following commands register pages with HTML content:
Command |
Description |
vizhtml.registerFile(url, filename, directory=None) |
Registers a page with the vizhtml server that uses an HTML file for content.
url: The path portion of the page's URL. See the server and URL section for further details about URLs.
filename: The name of the HTML file.
directory: The directory where page resources are saved. |
vizhtml.registerCode(url, code, directory=None) |
Registers a page with the vizhtml server that uses HTML code for content.
url: The path portion of the page's URL. See the server and URL section for further details about URLs.
code: A string that contains HTML code.
directory: The directory where page resources are saved. |
In the following example, HTML code that contains a form is registered with the server. Once the form is submitted from a browser, it's data is collected in Vizard.
For testing on a local browser use 'localhost' or the loopback address:
http://localhost:8080/vizhtml/form_submit
http://127.0.0.1:8080/vizhtml/form_submit
For remote browsers replace computer name or IP address with the Vizard machine's name or address
http://computer name:8080/vizhtml/form_submit
http://IP Address:8080/vizhtml/form_submit
When an HTTP request (e.g. page request, resource request, form submission) arrives at vizhtml's HTTP server, it get's handled so the appropriate action is taken.
By registering your own handler with the server you can have perform custom actions when a request arrives. The handler will be passed a request object that provides information about the browser's request and methods to send content back to the browser.
The following command registers a handler with the server:
Command | Description |
vizhtml.registerHandlerClass(url, handler_class directory=None) | Registers a custom handler class with the vizhtml server.
url: The path portion of the URL. See the server and URL section for further details about URLs.
handler_class: A custom handler class that extends the vizhtml.PageRequestHandler class.
directory: The directory where page resources are saved. |
The custom handler should inherit from vizhtml.PageRequestHandler and override it's handle_request method. This method is passed a request object that is an instance of vizhtml.VizardHTTPRequestHandler.
Note: The handle_request method is called from a separate thread than the main thread.
VizardHTTPRequestHandler inherits from Python's BaseHTTPRequestHandler class and adds the following methods and attributes:
Attribute | Description |
<VizardHTTPRequestHandler>.form_event | The form event if the request is from a form submission, otherwise None. |
<VizardHTTPRequestHandler>.resource_path | The relative path of a resource request from custom page (e.g. images). |
Method | Description |
<VizardHTTPRequestHandler>.send_html_code(code) | Sends the specified HTML code to the browser. |
<VizardHTTPRequestHandler>.send_html_file(filename) | Sends the specified HTML file to the browser. |
<VizardHTTPRequestHandler>.send_local_resource(filename, mimetype=None) | Sends the specified resource file to the browser.
mimetype: If this is None it will be guessed from the filename. Otherwise it must be a 2-item tuple containing the HTTP content type and content encoding strings. |
The example code below uses a custom handler to update content on a web page after a form submission. The data retrieved from the form's text field is placed back into the page and Vizard's frame count is displayed.
For testing on a local browser use 'localhost' or the loopback address:
http://localhost:8080/vizhtml/custom_handler
http://127.0.0.1:8080/vizhtml/custom_handler
For remote browsers replace computer name or IP address with the Vizard machine's name or address
http://computer name:8080/vizhtml/custom_handler
http://IP Address:8080/vizhtml/custom_handler