When working with Formidable Forms on WordPress, moving complex forms with formulas from one form to another or from one website to another can pose a challenge. The built-in export/import utilities of Formidable Forms, while robust, often fail to preserve formulas during the transfer. This is mainly because the formulas in Formidable Forms are typically tied to field IDs, which can vary from one form to another, even on the same site. In this article, we’ll explore a method to efficiently move these formulas using a more code-based approach to ensure your formulas are correctly transferred and remain functional.

Understanding the Problem with Field IDs

Formidable Forms identifies each field by an ID number that is unique within a form. When formulas reference these IDs, they become inherently linked to that specific form’s structure. If you export a form and import it into another WordPress installation or another form, the field IDs might not match, leading to broken formulas.

Using Entry Keys as Identifiers

One possible workaround to maintain the integrity of formulas across different forms or websites is by using entry keys instead of IDs. Entry keys are similar to variable names used in programming and must be unique within each form. This method involves manually replacing all field ID references in your formulas with these entry keys, which is time-consuming and prone to errors, especially in complex forms with many fields and intricate formulas.

A Better Solution: Automating Formula Transfer

To simplify and reduce the error rate in transferring Formidable Forms with formulas, a more automated approach can be adopted. This involves writing a script that manipulates the XML export file of the form. Here’s a step-by-step explanation of how this can be done:

Step 1: Export the Original Form

First, export the form you wish to transfer from the original WordPress site. Formidable Forms allows you to export the form as an XML file, which will include all the form’s structure, settings, and formulas.

Step 2: Prepare the Script

The script will read the XML file, identify all formulas, and replace field IDs with a more consistent identifier (like entry keys or a similar mechanism). The choice of programming language for the script can vary (PHP or Python are good candidates due to their XML handling capabilities), but the essential functionality will involve parsing XML and string manipulation.

Step 3: Identify and Replace Field IDs

Write a function within your script that scans through each formula and replaces the field IDs with the corresponding entry keys. This requires a mapping from field IDs to entry keys, which you might need to prepare beforehand or generate dynamically by parsing field definitions within the XML.

Step 4: Export the Modified XML

After all references in the formulas have been updated, the script should save the modified form structure back into an XML file, ready for import.

Step 5: Import the Modified Form

Finally, import the modified XML file into the target WordPress site. The form should now retain all its original functionality, including the working formulas.

Example Code Snippet

Below is a simple example of how such a script might look in PHP, focused on replacing IDs with keys:

$xml = simplexml_load_file('path_to_your_form.xml'); // Load your form XML
$mapping = [
    'field_id_1' => 'entry_key_1',
    'field_id_2' => 'entry_key_2',
    // Add more mappings as needed

foreach ($xml->formulas as $formula) {
    $originalFormula = $formula->value;
    foreach ($mapping as $id => $key) {
        $formula->value = str_replace("[".$id."]", "[".$key."]", $formula->value);
    echo "Updated formula: " . $formula->value . "\n";

// Save the modified XML