`function CF7ToDBData(siteUrl, formName, search, user, pwd) {
var response = fetchCF7ToDBCSVResponse(siteUrl, formName, search, user, pwd);
var contents = response.getContentText();
if (contents == ‘-1’ || contents == ‘0’) {
return “Error Code from WordPress: ” + contents;
}
if (response.getResponseCode() >= 200 && response.getResponseCode() < 300) {
return csvToArray(contents);
}
else {
if (response.getResponseCode() == 401) {
return “Error: Login Failed”;
}
if (response.getResponseCode() == 404) {
return “Error: Bad URL”;
}
return “Error: HTTP ” + response.getResponseCode();
}
}
function fetchCF7ToDBCSVResponse(siteUrl, formName, search, user, pwd) {
var encformName = encodeURI(formName).replace(new RegExp(“%20”, “g”), “%2B”);
var url = siteUrl + “/wp-login.php?redirect_to=wp-admin/admin-ajax.php%3Faction%3Dcfdb-export%26form%3D” + encformName;
if (search != null && search != ”) {
url += ‘%26search%3D’ + encodeURI(search);
}
return UrlFetchApp.fetch(
url,
{
method: “post”,
payload: “log=” + encodeURI(user) + “&pwd=” + encodeURI(pwd)
});
}
// Taken from: http://stackoverflow.com/questions/1293147/javascript-code-to-parse-csv-data
function csvToArray(text) {
text = CSVToArray(text, “,”);
var arr = [];
var c = [];
for (var i = 0; i < text.length – 1; i++) {
c = [];
for (var j = 0; j < text[0].length; j++) {
c.push(text[i][j]);
}
arr.push(c);
}
return arr;
}
// Taken from: http://stackoverflow.com/questions/1293147/javascript-code-to-parse-csv-data
// This will parse a delimited string into an array of
// arrays. The default delimiter is the comma, but this
// can be overriden in the second argument.
function CSVToArray(strData, strDelimiter) {
// Check to see if the delimiter is defined. If not,
// then default to comma.
strDelimiter = (strDelimiter || “,”);
// Create a regular expression to parse the CSV values.
var objPattern = new RegExp(
(
// Delimiters.
“(\\” + strDelimiter + “|\\r?\\n|\\r|^)” +
// Quoted fields.
“(?:\”([^\”]*(?:\”\”[^\”]*)*)\”|” +
// Standard fields.
“([^\”\\” + strDelimiter + “\\r\\n]*))”
),
“gi”
);
// Create an array to hold our data. Give the array
// a default empty first row.
var arrData = [
[]
];
// Create an array to hold our individual pattern
// matching groups.
var arrMatches = null;
// Keep looping over the regular expression matches
// until we can no longer find a match.
while (arrMatches = objPattern.exec(strData)) {
// Get the delimiter that was found.
var strMatchedDelimiter = arrMatches[ 1 ];
// Check to see if the given delimiter has a length
// (is not the start of string) and if it matches
// field delimiter. If id does not, then we know
// that this delimiter is a row delimiter.
if (
strMatchedDelimiter.length &&
(strMatchedDelimiter != strDelimiter)
) {
// Since we have reached a new row of data,
// add an empty row to our data array.
arrData.push([]);
}
// Now that we have our delimiter out of the way,
// let’s check to see which kind of value we
// captured (quoted or unquoted).
if (arrMatches[ 2 ]) {
// We found a quoted value. When we capture
// this value, unescape any double quotes.
var strMatchedValue = arrMatches[ 2 ].replace(
new RegExp(“\”\””, “g”),
“\””
);
} else {
// We found a non-quoted value.
var strMatchedValue = arrMatches[ 3 ];
}
// Now that we have our value string, let’s add
// it to the data array.
arrData[ arrData.length – 1 ].push(strMatchedValue);
}
// Return the parsed data.
return( arrData );
}
Daarna diende ik in de spreadsheet zelf op een cel volgende formule in te geven.
=CF7ToDBData(“http://ivvoh.be”, “Registratieformulier oud leerling”, “”, “user”, “pwd”)
ik heb dit gedaan, en nadat ik op enter gedrukt heb krijg ik de error melding “parseerfout”.
Ik heb het al enkele keren opnieuw gedaan, maar blijf steeds dezelfde foutmelding krijgen.
Bednakt voor jullie hulp
Jens
jens.decaluwe