Skip to content

Instantly share code, notes, and snippets.

@fahdi
Forked from ano/ReadMe.md
Created January 24, 2024 04:44
Show Gist options
  • Save fahdi/6f282d7a61e704d1543cab0661fe8f4a to your computer and use it in GitHub Desktop.
Save fahdi/6f282d7a61e704d1543cab0661fe8f4a to your computer and use it in GitHub Desktop.
Formidable Forms Manage Entries Script

Introduction

A single page standalone PHP script to help manage formidable forms data in the front-end.

Usage

Add Entry

To add a see the URL below, note that

Edit Entry

To edit an existing entry see the URL below, note that

List Entries

List form records URL, note that

Set Up

Here is what you need to enable to manage data in the front-end in the formidable forms plugin settings in wordpress. Update Settings Allow Front-End Editing On Update

<?php
/**
* Return formidable forms responses based on requests
*/
function route_formidable_requests(){
$response["edit_link"] = "#";
//Display table entry
if(isset($_REQUEST["form_id"]) && isset($_REQUEST["frm_action"]) && $_REQUEST["frm_action"] === "list" ){
$form_id = (int) $_REQUEST["form_id"];
$response['table'] = get_form_entries($form_id);
}
//Display a form
else if(isset($_REQUEST["form_id"])){
$form_id = (int) $_REQUEST["form_id"];
$response['table'] = get_form($form_id);
}
//Display single entry
else if (isset($_REQUEST["entry_id"])) {
$entry_id = (int) $_REQUEST["entry_id"];
$response['table'] = get_entry($entry_id);
$response["edit_link"] = create_edit_link($entry_id);
}
//Error Response
else {
$response['table'] = "No entry id has been set";
}
return $response;
}
/**
* Display a Formidable Forms list of entries, allow editing and deleting if the wordpress user is logged in
*/
function get_form_entries($form_id){
return FrmProEntriesController::get_form_results(
array(
"id"=> $form_id,
"edit_link"=>"Edit",
"delete_link"=>"Delete",
"confirm"=>"Are you sure you want to delete this record?"
)
);
}
/**
* Display a Formidable Forms Form for data entry
*/
function get_form($form_id){
return FrmFormsController::show_form($form_id, $key = '', $title=1, $description=true);
}
/**
* Display a single Formidable Forms Entry
*/
function get_entry($entry_id){
return FrmProEntriesController::show_entry_shortcode(
array(
'id' => $entry_id,
'plain_text' => 0,
'format' => 'text',
"include_extras" => "page, section, html"
)
);
}
/**
* Create a data edit link for a single entry
*/
function create_edit_link($entry_id){
$edit_url = WP_PATH . "wp-admin/admin.php?page=formidable-entries&frm_action=edit&id=" . $entry_id;
return "<a href='{$edit_url}'>Edit Record</a>";
}
?>
<?php
/*
* Load WordPress Environment
*/
define('WP_PATH', '../');
define('WP_USE_THEMES', false);
require(WP_PATH . 'wp-load.php');
/**
* Load Formidable Forms plugin functions
* Display Form: index.php?frm_action=add&form_id=7
* Display Form Entries: index.php?frm_action=list&form_id=7
* Display Form Entries with Search Filter: index.php?frm_action=list&form_id=7&search=JIO 20-01
* Display Single Entry: index.php?frm_action=view&entry_id=35
* Edit an Existing Entry: index.php?frm_action=edit&form_id=7&entry=23
*/
require_once("formidable_functions.php");
$response = route_formidable_requests();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Formidable Records</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|Quicksand:300,400,500,700" rel="stylesheet">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<section>
<p><?php echo $response['table'];?></p>
</section>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Raleway" />
<link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
<link rel="stylesheet" href="styles.css"> <!-- -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/responsive/2.2.6/css/responsive.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="https://learn.norma.cloud/wp-content/plugins/formidable/css/formidableforms.css?ver=12181836" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="//cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/responsive/2.2.6/js/dataTables.responsive.min.js"></script>
<script>
function $_GET(param){
const queryString = window.location.search; //console.log(queryString);
const urlParams = new URLSearchParams(queryString);
return urlParams.get(param);
}
$(document).ready( function () {
$('table.form_results').addClass( "responsive" ); //Make table responsive
var table = $('table.form_results').DataTable({
responsive: true
});
if($_GET("search")) table.search( $_GET("search") ).draw();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment