Description Usage Arguments Details Value See Also Examples
Print out a form and store the subject's inputs in a data frame, after checking for errors
1 | form_stage(page, fields, titles = NULL, data_frame, name = "No name")
|
page |
A character vector containing HTML, or a function to be called
with parameters |
fields |
A character vector of field names, or a list like
|
titles |
A list of field titles, like |
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. |
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
field_title
is the field name itself (the name of the
corresponding list element) unless a list of titles was supplied.
value
is the value of the corresponding field in the form
submitted by the user. This will be a length 1 character string.
id
and period
are self-explanatory
params
is the full list of parameters
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.
An object of class FormStage
Other stages: NEXT
, WAIT
,
stage
; checkpoint
;
period
; program
;
text_stage
; timed
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)
})
))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.