function createFile($data, $columns, $apiKey) { $jotform = new JotForm($apiKey); $userInfo = $jotform->getUser(); $filename = $userInfo['username'] . '_' . rand(); $fp = fopen('CSVs/' . $filename . '.csv', 'w'); fputcsv($fp, $columns); $count = 0; $limit = 2000; $limited = false; foreach ($data as $submission_id => $submission) { if (++$count > $limit) { $limited = true; break; } $outputLine = array(); foreach ($columns as $title) { if (array_key_exists($title, $submission)) { array_push($outputLine, $submission[$title]); } else { array_push($outputLine, ''); } } fputcsv($fp, $outputLine); } fclose($fp); $warning = $limited ? "CSV file limited to " + $limit + " lines" : false; $data = array('warning' => $warning, 'filename' => $filename); echo json_encode($data); }
/** * Handle and read uploaded file * @param array - fileArray from form * @param array - postArray from form */ function handleUpload($_FILES, $_POST) { require_once "JotForm.php"; $path = mktime() . '_' . $_FILES['file']['name']; $key = $_POST['APIkey']; $form = $_POST['formID']; $jot = new JotForm($key); $error = ""; if (move_uploaded_file($_FILES['file']['tmp_name'], $path)) { $fileType = getFileType($path); $columns = array(); if ($fileType == 'csv') { if (($handle = fopen($path, "r")) !== FALSE) { if (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { foreach ($data as $title) { array_push($columns, $title); } } $error = 'File must contain at least two rows - the first represents the field titles'; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $error = ''; $result = $jot->createFormSubmissions($form, writeData($data, $columns)); } fclose($handle); } else { $error = 'Could not open file'; } } else { require_once 'Excel/reader.php'; $excel = new Spreadsheet_Excel_Reader(); $excel->read($path); if ($excel->sheets[0]['numRows'] > 1) { for ($i = 1; $i <= $excel->sheets[0]['numCols']; $i++) { $title = $excel->sheets[0]['cells'][1][$i]; array_push($columns, $title); } for ($i = 2; $i <= $excel->sheets[0]['numRows']; $i++) { $data = array(); for ($j = 1; $j <= $excel->sheets[0]['numCols']; $j++) { array_push($data, $excel->sheets[0]['cells'][$i][$j]); } $jot->createFormSubmissions($form, writeData($data, $columns)); } } else { $error = 'File must contain at least two rows - the first represents the field titles'; } } } else { $error = 'No File Found'; } if (strlen($error) > 0) { return $error; } else { return 'none'; } }
function jotform_mysqldump($apiKey, $formID) { // get a list of questions $jotformAPI = new JotForm($apiKey); $form = $jotformAPI->getForm($formID); $formTitle = $form['title']; $questions = $jotformAPI->getFormQuestions($formID); $new_questions = array(); $ignored_fields = array("control_head", "control_button", "control_pagebreak", "control_collapse", "control_text"); $i = 0; foreach ($questions as $q) { if (!in_array($q['type'], $ignored_fields)) { array_push($new_questions, $q); $ordered_questions[$q['order']] = $i++; } } $questions = $new_questions; //print "<pre>"; //print_r( $questions ); // prepare CREATE TABLE code $table = mysql_fieldname_format($formTitle); $sql = "CREATE TABLE IF NOT EXISTS `" . $table . "` (\n"; $fields_sql = array(); $fields = array(); foreach ($ordered_questions as $order => $i) { $mysql_type = "varchar(255)"; if ($questions[$i]['type'] == "control_textarea") { $mysql_type = "text"; } array_push($fields, $questions[$i]['text']); array_push($fields_sql, "\t`" . mysql_fieldname_format($questions[$i]['text']) . "` " . $mysql_type); } $sql .= implode(",\n", $fields_sql); $sql .= "\n);\n\n"; //print $sql; // get submission data $submissions = $jotformAPI->getFormSubmissions($formID); //print_r($submissions); foreach ($submissions as $s) { $insert = "INSERT IGNORE INTO `{$table}` (\n"; $keys = array(); $values = array(); foreach ($fields as $k) { //print "<li>$k".$s['fields'][$k]; array_push($keys, "`" . mysql_fieldname_format($k) . "`"); array_push($values, "'" . mysql_real_escape_string($s['fields'][$k]) . "'"); } $insert .= implode(", ", $keys); $insert .= "\n) VALUES (\n"; $insert .= implode(", ", $values); $insert .= "\n);\n\n"; $sql .= $insert; } return $sql; }
function getSummary($formID, $questionID) { $jotform = new JotForm("yourAPIKey"); $submissions = $jotform->getFormSubmissions($formID); foreach ($submissions as $id => $submissionDetails) { $answer = isset($submissionDetails["answers"][$questionID]["answer"]) && $submissionDetails["answers"][$questionID]["answer"] != "" ? $submissionDetails["answers"][$questionID]["answer"] : "Not Answered"; $answersArray[$answer] = isset($answersArray[$answer]) ? $answersArray[$answer] + 1 : 1; } $result = ""; arsort($answersArray); foreach ($answersArray as $key => $value) { $percentages[$key] = round($answersArray[$key] * 100 / count($submissions), 1); $result .= "%{$percentages[$key]} {$key}, "; } return sprintf("In %d submissions, there are %d different answers for question #%d : %s \n ", count($submissions), count($answersArray), $questionID, trim($result, ' ,')); }
/** * Sample link is http://www.yourserver.com/confirm.php?id={id} * {id} tag will automatically be replaced by the real submission id when * the email notifications are fired. */ function confirmSubmission() { // Your (full-access) JotForm API Key for this application $apiKey = '6a912a693094ac1696f65e93d89b3e3a'; // Submission ID passed from the confirmation link $subID = $_GET['id']; // Question ID for the field designated as the 'confirmed' flag $questionID = '3'; // Value assigned to a verified submission $confirmValue = 'Yes'; $jotformAPI = new JotForm($apiKey); $result = $jotformAPI->editSubmission($subID, array($questionID => $confirmValue)); if (!is_array($result)) { var_dump($result); } }
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Enquiries</title> <link href="admincss.css" rel="stylesheet" type="text/css"> </head> <body> <div align="center"> <div><a href="/index.php">HOME</a> | <a href="/admin/index.php">ADMIN</a> | <a href="/admin/index.php?action=log_out">LOGOUT</a></div> <p></p> <?php try { include "JotForm.php"; $jotformAPI = new JotForm("c9e8ae4b227d12360d9611e5eebfb1de"); $submissions = $jotformAPI->getFormSubmissions(51760713131951); if (sizeof($submissions) < 1) { echo "No Enquiries Found"; } else { ?> <table border=1 cellpadding="5"><tr><th>Enquiry Date</th><th>Enquirer</th><th>Email</th><th>Phone</th><th>Interest</th><th>Message</th> <?php foreach ($submissions as $submission) { $submissionID = $submission["id"]; $submissionDate = date_create($submission["created_at"]); $submissionDatePrint = date_format($submissionDate, "d M Y"); $answers = $submission["answers"]; $submitterName = $answers[4]["answer"]["first"] . " " . $answers[4]["answer"]["last"]; $submitterEmail = $answers[5]["answer"];
function getSubmissions($apiKey, $formID) { $jotformAPI = new JotForm($apiKey); $submissions = $jotformAPI->getFormSubmissions($formID, 0, 10000); return $submissions; }
do_settings_sections('dx-plugin-base'); ?> <input type="submit" value="<?php _e("Save", 'dxbase'); ?> " /> </form> <!-- end of #dxtemplate-form --> <?php try { $jc_settings = get_option('jc_setting', ''); $jt = new JotForm($jc_settings['jc_api_key']); $key = $jc_settings['jc_api_key']; if (!$key == "") { echo "<script> JF.initialize({ apiKey: '{$key}' }) </script>"; } $users = $jt->getUser(); //var_dump($users); echo '<hr/>'; echo '<h3> Account Information </h3>'; echo '<table width="600px" class="sc">'; foreach ($users as $key => $user) { printf(' <tr> <th scope="row">%s</th> <td>%s</td> </tr>', $key, $user);
<?php if (!class_exists('WP_List_Table')) { require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } $jc_settings = get_option('jc_setting', ''); $jt = new JotForm($jc_settings['jc_api_key']); $forms = $jt->getForms(); // TODO : check if $forms not empty $index = 0; foreach ($forms as $form) { $form['shortcode'] = '[jotform id="' . $form['id'] . '"]'; $form['ID'] = $form['id']; if ($form['status'] == 'DELETED') { unset($form[0]); } else { $forms_update[] = $form; } $index++; } $data = $forms_update; $jforms = new Form_List_Table(); $jforms->prepare_items($data); ?> <div class="wrap"> <div id="icon-users" class="icon32"><br/></div> <h2><?php _e("JotForms", 'dxbase'); ?> </h2> <p> <button onclick="JotformAnywhere.launchFormBuilder();" id="embedJotform" class="button button-primary button-large">Add Form</button></p>