Vizard 8 » Reference » Graphical user interfaces (GUIs) » HTML and web browsers » Collecting form data
8.0

Collecting Form Data

When an HTML form in a remote browser or embedded HTML window is submitted, a vizhtml.FORM_SUBMIT_EVENT is generated. The event can be handled using either a task or callback function.

Waiting for a form submission in a viztask function

Task functions, from the viztask library, are useful for controlling program flow. Use the following command to create a viztask condition that waits for a form submission:

Command

Description

vizhtml.waitFormSubmit()

Waits until a form submit event occurs. The yielded command returns a viz.Data object that holds the form data.   

The names of properties in the returned data object match the names of input fields in the HTML form. For example, if the HTML form contains a text field named occupation:

<input type="text" name="occupation">

the code below would store the value from that field after the form is submitted:

def myFormTask():

    # Display input form
    vizhtml.displayCode(html)

    # Wait for form submission
    d = yield vizhtml.waitFormSubmit()

    # Get data from form
    occupation = d.occupation

viztask.schedule( myFormTask() )

Handling a form submission in a callback function

Use the command below to register a callback function for a form submission event:

Command

Description

vizhtml.onFormSubmit(func,

                              *args,

                              **kw)

Registers a callback function for a form submission event:

 

func: The function being registered. An event object e, holding form data, will be passed to this callback function.

 

*args: Optional arguments to pass to the registered function.

 

**kw: Optional keyword arguments to pass to the registered function.

The names of properties in the event object e passed to the callback function match the names of input fields in the HTML form. For example, if the HTML form contains a text field named occupation:

<input type="text" name="occupation">

the code below would store the value from that field after the form is submitted:

# Display input form
vizhtml.displayCode(html)

def HandleForm(e):

    occupation = e.occupation

vizhtml.onFormSubmit(HandleForm)

vizhtml introduction

HTML Forms in Vizard

HTML Forms in a remote browser

Collecting form data

Local HTTP server and URLs

WebSockets