Created
September 15, 2015 21:02
-
-
Save saltlakeryan/736c874db5fb1bee5f4c to your computer and use it in GitHub Desktop.
pull csv from formidable forms with php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_form_entries($baseurl, $username, $password, $uid, $formid) { | |
$headerfile = tempnam("/tmp", "formidable-header"); | |
$cookiefile = tempnam("/tmp", "formidable-cookie"); | |
$csvfile = tempnam("/tmp", "formidable-csv"); | |
$login_cmd = "curl -s -D $headerfile -c $cookiefile 'http://$baseurl/wp-login.php' --data 'log=$username&pwd=$password&testcookie=1' -H 'Cookie: wp-settings-time-$uid=2829600000; wordpress_test_cookie=WP+Cookie+check' 2> /dev/null"; | |
$pull_csv_cmd = "curl -s -D $headerfile -b $cookiefile -o $csvfile -c $cookiefile 'http://$baseurl/wp-admin/admin-ajax.php?frm_action=0&action=frm_entries_csv&form=$formid'"; | |
exec($login_cmd, $output, $status); | |
if ($status != 0) { | |
throw new Exception("Can't login"); | |
} | |
exec($pull_csv_cmd, $output, $status); | |
if ($status != 0) { | |
throw new Exception("Can't pull CSV data"); | |
} | |
$data = parse_csv($csvfile); | |
unlink($headerfile); | |
unlink($cookiefile); | |
unlink($csvfile); | |
return $data; | |
} | |
function parse_csv($file) { | |
$rows = []; | |
if (($handle = fopen($file, "r")) !== FALSE) { | |
while (($row = fgetcsv($handle, 0)) !== FALSE) { | |
$rows[] = $row; | |
} | |
fclose($handle); | |
} | |
return $rows; | |
} | |
$output = get_form_entries("mywordpress-site.com", "myusername", "mypassword", "299", "11"); | |
var_dump($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment