Scroll to navigation

Webapp.autoFill(3kaya) Kaya module reference Webapp.autoFill(3kaya)

NAME

Webapp::autoFill - Automatically fill a HTML form

SYNOPSIS

Void autoFill( ElementTree form, DataSource mainvars, Dict<String, [String]> extravars=Dict::new() )

ARGUMENTS

form The form element (or a subset of that if you only wish to automatically fill a part of the form.
mainvars The data source to use (e.g. DataPost )
extravars An optional dictionary mapping keys to lists of values, to allow a form to be automatically filled from a database. You may or may not need to use DataNone as your main data source in this case.

DESCRIPTION

Automatically fill a HTML form based on data from a particular data source. This makes it easy to construct web forms with error handling - see the webapp tutorial for more information.

ElementTree OnHello(Int dummy) {
div = anonymousBlock; // we create this temporarily.
fname = incomingValue("fname",DataPost);
lname = incomingValue("lname",DataPost);
if (fname != "" && lname != "") {
p = addParagraph(div,"Hello "+fname+" "+lname);
return p;
} else {
form = HelloForm();
// if they entered one of first and last name, make sure it's still in the form
autoFill(form,DataPost);
return form;
}
}

ElementTree helloForm() {
parent = anonymousBlock;
form = addLocalForm(parent);
f1 = addFieldset(form,"Who are you?");
input = addLabelledInput(f1,"Your First Name",InputText,"fname","",0);
input = addLabelledInput(f1,"Your Last Name",InputText,"lname","",0);
submit = addLocalControlInput(f1,"Say hello",OnHello,1);
return form;
}

AUTHORS

Kaya standard library by Edwin Brady, Chris Morris and others (kaya@kayalang.org). For further information see http://kayalang.org/

LICENSE

The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1 or any later version) as published by the Free Software Foundation.

RELATED

WebCommon.DataSource (3kaya)
August 2014 Kaya