form_stage: Print out a form and store the subject's inputs in a data...

Description Usage Arguments Details Value See Also Examples

Description

Print out a form and store the subject's inputs in a data frame, after checking for errors

Usage

1
form_stage(page, fields, titles = NULL, data_frame, name = "No name")

Arguments

page

A character vector containing HTML, or a function to be called with parameters id, period, params, errors.

fields

A character vector of field names, or a list like list(field_name=check_function, ...)

titles

A list of field titles, like list(field_name=title,...)

data_frame

The quoted string name of the data frame to be updated. This should exist in the global environment.

name

optional name of the stage.

Details

When the subject first arrives, the text or file page is displayed. After the form is submitted, it is checked for errors, as follows: each member of the list fields is called as a function, with arguments (field_title, value, id, period, params). Here

If the function returns NULL the field is OK. If the function returns a character vector, this is treated as a vector of error messages.

If there are any error messages, page is redisplayed. If there are no error messages, the data frame named in data_frame is updated: in the row with id==id && period==period, the columns named by fields get the values passed in by the user.

b_brew and similar functions can be used as arguments to page.

is_whole_number and similar functions return functions suitable for use in the fields list.

Value

An object of class FormStage

See Also

Other stages: NEXT, WAIT, stage; checkpoint; period; program; text_stage; timed

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
mydf <- data.frame(id=rep(1:5, each=5), period=rep(1:5, times=5),
     username=NA_character_, password=NA_character_)

s1 <- form_stage(page=b_brew("myform.html"), data_frame="mydf",
 fields=list(
   username=length_between(8, 15),
   password=all_of(length_at_least(8), function(name, val, ...) {
     if (val=='password') return("Password should not be 'password'")
     if (grepl('&[A-Za-z0-9]$', val)) return("Password should contain at
           least one non-numeric character")
     return(NULL)
     })
))

hughjonesd/betr documentation built on May 17, 2019, 9:11 p.m.