Tag Archives: Formidable Pro

Store uploaded file URL in custom field

I had to tweak the code here a little to get the desired result. For some reason, wp_get_attachment_url() method wasn’t returning the correct values. My version of the code is given below for reference:

add_filter( 'frm_new_post', 'create_a_custom_field', 10, 2 );
function create_a_custom_field( $post, $args ) {
$field_id = 89; //replace 89 with the correct field id
if ( isset( $_POST['item_meta'][ $field_id ] ) && !empty( $_POST['item_meta'][ $field_id ] ) ) {
$field_value = sanitize_text_field( $_POST['item_meta'][ $field_id ] );
$attachmentids = '';
foreach ($_POST['item_meta'][ $field_id ] as $value) {
$attachmentids=$attachmentids.','.$value;
}
$post['post_custom']['_product_image_gallery'] = $attachmentids;
}
return $post;
}

Hope this helps! Please let me know if there is a better way to achieve the same results.

Formidable integration with intercom.io

Intercom is a CRM platform that acts as the single channel between client and service provider. The tool can be used to manage, communicate and tag users in addition to a variety of other features.

My requirement was to tag intercom users once a formidable entry is marked as approved. The idea is to identify the logged in WP user and tag the corresponding user entry in intercom. Key pieces to the integration are given below:
1) A view with single field edit links.
2) Once the the entry is updated, based on certain conditions, send data to intercom and tag users.
3) Intercom API documentation can be found here.
4) Intercom’s PHP library and installation instructions are in Github here.

Code snippet
require_once 'intercom/vendor/autoload.php';
use Intercom\IntercomBasicAuthClient;
add_action('frm_after_update_field', 'frm_trigger_entry_update'); //action triggered during entry update from view
function frm_trigger_entry_update($atts){
$entry = FrmEntry::getOne($atts['entry_id']);
do_action('frm_after_update_entry', $entry->id, $entry->form_id); //callback to FP frm_after_update_entry hook
}
add_action('frm_after_update_entry', 'send_to_intercom', 10, 2); //action triggered after update entry
function send_to_intercom($entry_id, $form_id){
$intercom = IntercomBasicAuthClient::factory(array( //intercom initialization
'app_id' => 'app_id',
'api_key' => 'app_key'
));
global $wpdb,$frm_entry,$frm_entry_meta;
//replace 28, 342, 285, 341 with your form and field ids respectively
if($form_id == 28 && FrmEntryMeta::get_entry_meta_by_field($entry_id, 342) == 'Approved') {
$tag_user = new WP_User( FrmEntryMeta::get_entry_meta_by_field($entry_id, 285) );
$intercom->tagUsers(array( //call to 'tagUsers' intercom api function
"name" => FrmEntryMeta::get_entry_meta_by_field($entry_id, 341).": Approved",
"users" => array(
array("email" => $tag_user->user_email)
)
));
}
}
}

Hope this helps! Please feel free to share your experiences and let me know if there are better ways to use the intercom API.

Search for repeating sections in Formidable Pro

One of the pain areas while working with repeating sections in Formidable Pro is that the fields contained in repeatable sections are not searchable.

Unable to search for certain fields in a form really defeats the purpose of including such fields in the first place. Formidable team is going to roll out a fix in the next release, but there is a workaround to fix it locally unless the next version of FP is made available.

Please note that the changes suggested here are to the core FP source and kindly ensure to take a back-up of entire FP source code. The steps are given below:

1. Go into formidable/pro/classes/helpers/FrmProAppHelper.php. Near line 448, you’ll see this:
$new_ids = FrmEntryMeta::getEntryIds( $where_statement, '', '', true, $filter_args );
Right above it, add this:
$filter_args['return_parent_id'] = ( $where_field->form_id != $args['form_id'] );

2. Next, go into formidable/classes/models/FrmEntryMeta.php. Near line 293, you’ll see this:
$query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id';
Replace it with this:
$defaults = array( 'return_parent_id' => false );
$args = array_merge( $defaults, $args );
if ( $args['return_parent_id'] ) {
$query[] = $unique ? 'DISTINCT(e.parent_item_id)' : 'e.parent_item_id';
} else {
$query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id';
}

This should fix the search issue with fields in repeatable sections. Hope this helps! Please let me know if there is a better solution to the same problem.

UltimateClientManager plugin

Riding on my proof of concept and research, I built v1.0 of my plugin for UCM.

My requirement is to build a plugin to manage Leads for different clients. There are options to add and modify leads. Currently, the plugin is being scaled so that Leads can flow back and forth between different systems. Technically, this will involve integration (Read/Write) to Formidable Pro as all the leads also sync to Formidable database as part of a separate solution.

Please let me know if you have questions and I will try to address individual queries. I shall be writing more on this subject once integration with Formidable Pro is complete.

PHPExcel reports generation

I worked on an assignment where the desire was to generate excel report of Formidable Pro entries from front end view. After some research, I chose PHPExcel as the library of my choice. The reason for using PHPExcel is a mature library combined with comprehensive documentation. Once you download the library and explode the zip file, all you require is the core, i.e. the *Classes* folder uploaded to your custom project. Include the library in your custom code using the lines below
ini_set('max_execution_time', 0); //this is optional and may be required if the data set is huge. It increases the script execution time
require_once 'path/to/Classes/PHPExcel.php';
//your custom code to generate report

I found PHPExcel to be quite efficient and mature for generating reports for analytics. However, please feel free to share your experience and let me know if there is a better library which can deliver the same results more efficiently.

Formidable entry creation date

Quick tip to fetch entry creation date with Formidable API.
global $frm_entry,$frm_entry_meta;
$entries = $frm_entry->getAll("form_id=50"); //replace 50 with your form id
foreach($entries as $entry){
echo $entry->created_at; //entry creation date generally in format('Y-m-d H:i:s')
}

Hope this helps! Please share your experience and tips or tricks while working with FP.

Create Formidable entries from outside using nusoap web service

Nusoap makes designing web services in PHP easy. My requirement was to use Nusoap to design a web service that an external system can use to post entries in Formidable.
Nusoap can be downloaded here. Once downloaded, explode the zip file and upload *lib* folder to the project directory. We will be creating two files: postdata.php and createfpentry.php. The first file will act as the client to post requests. The latter will act as the web service server to handle post requests and insert formidable entries.
postdata.php
<?php
require_once ('lib/nusoap.php'); //imports the nusoap library
//set the post parameter
$param = array( 'fpformfieldslist' => array( 'v1' => trim($_GET['<var1>']),
'v2' => trim($_GET['<var2>']),
'v3' => trim($_GET['<var3>'])
)
);
$client = new nusoap_client('<hostname>/createfpentry.php'); //new object referring web service server
$response = $client->call('insert_fp_entry',$param); //invoke insert_fp_entry method from the server
//Process result
if($client->fault) {
//echo fault code and fault string: $client->faultcode and $client->faultstring
}
else {
echo $response; //echo response on successful web service call
}
?>

createfpentry.php
<?php
require_once ('lib/nusoap.php'); //import nusoap library
require_once( $_SERVER['DOCUMENT_ROOT'] . '/path/to/wp-load.php' ); //load WordPress from outside
$server = new soap_server; //server object
$server->register('insert_fp_entry'); //register insert_fp_entry method
function insert_fp_entry($fpformfieldslist) {
global $frm_entry, $frm_entry_meta;
$isCreated = $frm_entry->create(array(
'form_id' => 25, //replace 25 with your form id
'item_meta' => array(
152 => $fpformfieldslist['v1'], //replace 152 with your field id. You can set other fields with values equal to the different GET parameters
),
));
$result = 'Entry successfully created'; //you can make conditional edits to the response
return $result;
}
$server->service($HTTP_RAW_POST_DATA);
exit();
?>

The URL to access the web service is http://<host>/postdata.php?v1=test1&v2=test2&v3=test3. This will create an entry in formidable backend. The parameter values should be escaped for special characters.

Hope this helped! I shall be posting more on this subject in future posts. Please share your experiences and let me know if there is a better way to achieve similar results.

Autocomplete in Formidable Pro

Formidable Pro offers a fine feature called ‘enable autocomplete‘ for drop-down fields, the team making an extremely intelligent and efficient use of Chosen to drive this new field option.
However, one demerit of this feature is the lack of mobile support, ‘overkill’ being cited as one of the reasons for desktop only support and I respect their decision and whoever voted in favor of the cause.
This made me decide to implement my own custom solution with plain old jQuery and a text field (instead of drop-down). My requirement is to drive a ‘Data From Entries‘ field with ‘enable autocomplete’ checked for users to look up the values as they type. Also, users should be able to submit the data even if they enter a value not present in the drop-down, the new value finally getting added to the drop-down list.
As a first step to solve the problem, I added a text field to the form and bounded it to jQuery autocomplete. Second step was to write some PHP to make it the remote data source for autocomplete script. I used Formidable API to collect and return all field values from the form that was supposed to be the source for my data from entries field. This made my text field behave as a drop-down and also enabled users to add new values to the list. On form submission, I used Formidable hook to add the new entry to the list of entries.
A small demo is attached, the values you see are Formidable entries. Hope this helps! Please leave me a comment and let me know if there is a better way to achieve the same result.

Dynamic drop-downs in Formidable Pro

One quick way to implement dynamic drop-downs (where second drop-down entries are dependent on the selection of first drop-down value) is to use the Dynamic Fields feature of Formidable Pro.
Upside
a) Very quick and easy to implement.
b) Developer can avoid all the fancy ajax and get/post scripts to fetch values from database. This reduces cost of development and increases ease of maintenance.
Downside
a) This is a paid feature.

Hope this helps! Please leave me a comment and let me know if there is any other way to implement dynamic fields in formidable.