drupalr.postForm: Function to submit a Drupal form.

Description Usage Arguments Author(s) Examples

Description

This function allows a Drupal form to be submitted (e.g. user login form, node submission form, etc).

Usage

1
drupalr.postForm(d_url, d_path, form_id, pars, c, num=1)

Arguments

d_url

Base URL of the Drupal site.

d_path

Relative path to the Drupal page containing the form.

form_id

The Drupal form_id of the target form.

pars

CURL parameters for the fields int he form.

c

CURL handler of an authenticated session.

num

Offset of the form.

Author(s)

Ed Baker

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(d_url, d_path, form_id, pars, c, num=1) {
  #First load form to get token and build_id
  form <- RCurl::getURL(paste0(d_url, d_path), curl = c);
  data <- xml2::read_html(form)
  
  if (form_id == "comment_form") { num <- 3}
  
  data <- xml2::xml_find_first(data, paste0('//*[(@id = "',gsub("_", "-", form_id), '")]'));
  form_token <- unname(xml2::xml_attrs(xml2::xml_find_all(data, '//*[(@name = "form_token")]'))[[num]]['value'])
  form_build_id <- unname(xml2::xml_attrs(xml2::xml_find_all(data, '//*[(@name = "form_build_id")]'))[[num]]['value'])
  form_id <- unname(xml2::xml_attrs(xml2::xml_find_all(data, '//*[(@name = "form_id")]'))[[num]]['value'])
  
  i_pars=list(
    form_id=form_id,
    form_token=form_token,
    form_build_id=form_build_id
  );
  
  pars = c(pars, i_pars);
  
  html = RCurl::postForm(paste0(d_url, d_path), .params = pars, curl=c)
}

edwbaker/DrupalR documentation built on May 15, 2019, 11:04 p.m.