Plugin Directory

Changeset 3454441


Ignore:
Timestamp:
02/05/2026 10:05:10 AM (2 weeks ago)
Author:
shift8
Message:

Fixed bug where test fields were not saving

Location:
shift8-integration-for-gravity-forms-and-sap-business-one/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/readme.txt

    r3454222 r3454441  
    55* Requires at least: 5.0
    66* Tested up to: 6.8
    7 * Stable tag: 1.3.7
     7* Stable tag: 1.3.8
    88* Requires PHP: 7.4
    99* License: GPLv3
     
    104104
    105105== Changelog ==
     106
     107= 1.3.8 =
     108* **FIX**: Test data values now properly save with "Update Settings" button
     109* **ENHANCEMENT**: Test data fields moved into main settings form for consistent save behavior
    106110
    107111= 1.3.7 =
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/shift8-gravitysap.php

    r3454222 r3454441  
    44 * Plugin URI: https://github.com/stardothosting/shift8-gravitysap
    55 * Description: Integrates Gravity Forms with SAP Business One, automatically creating Business Partners from form submissions.
    6  * Version: 1.3.7
     6 * Version: 1.3.8
    77 * Author: Shift8 Web
    88 * Author URI: https://shift8web.ca
     
    2828
    2929// Plugin constants
    30 define('SHIFT8_GRAVITYSAP_VERSION', '1.3.7');
     30define('SHIFT8_GRAVITYSAP_VERSION', '1.3.8');
    3131define('SHIFT8_GRAVITYSAP_PLUGIN_FILE', __FILE__);
    3232define('SHIFT8_GRAVITYSAP_PLUGIN_DIR', plugin_dir_path(__FILE__));
     
    542542                    </td>
    543543                </tr>
     544               
     545                <?php if (!empty(rgar($settings, 'field_mapping'))): ?>
     546                <tr>
     547                    <th scope="row"><?php esc_html_e('Test Data Values', 'shift8-gravity-forms-sap-b1-integration'); ?></th>
     548                    <td>
     549                        <?php $this->render_test_data_table($settings); ?>
     550                    </td>
     551                </tr>
     552                <?php endif; ?>
    544553            </table>
    545554           
     
    13591368            <input type="hidden" name="subview" value="sap_integration" />
    13601369           
     1370            <!-- Hidden inputs for test values - populated from main form by JavaScript -->
     1371            <div id="test-values-hidden-container"></div>
     1372           
    13611373            <h3><?php esc_html_e('Test SAP Integration', 'shift8-gravity-forms-sap-b1-integration'); ?></h3>
    13621374            <p><?php esc_html_e('Send test data to SAP Business One to validate your field mapping configuration.', 'shift8-gravity-forms-sap-b1-integration'); ?></p>
    1363            
    1364             <?php $this->render_test_data_table($settings); ?>
     1375            <p class="description"><?php esc_html_e('Uses the Test Data Values from the settings above. Save your settings first to update test values.', 'shift8-gravity-forms-sap-b1-integration'); ?></p>
    13651376           
    13661377            <p class="submit">
     
    13711382            </p>
    13721383        </form>
     1384       
     1385        <script type="text/javascript">
     1386        jQuery(document).ready(function($) {
     1387            // Before submitting test form, copy test values from main form
     1388            $('#test-sap-form').on('submit', function() {
     1389                var container = $('#test-values-hidden-container');
     1390                container.empty();
     1391               
     1392                // Copy all test_values inputs from main form to hidden container
     1393                $('input[name^="test_values["]').each(function() {
     1394                    var name = $(this).attr('name');
     1395                    var value = $(this).val();
     1396                    container.append('<input type="hidden" name="' + name + '" value="' + value + '">');
     1397                });
     1398            });
     1399        });
     1400        </script>
    13731401        <?php endif; ?>
    13741402        <?php
     
    13831411    private function render_test_data_table($settings) {
    13841412        $field_mapping = rgar($settings, 'field_mapping', array());
     1413        $saved_test_values = rgar($settings, 'test_values', array());
    13851414       
    13861415        // Use the SAME field array as the mapping table
     
    14041433            'BPAddresses.Country' => 'US',
    14051434        );
     1435       
     1436        // Merge saved values over defaults (saved values take priority)
     1437        $test_values = array_merge($default_test_values, $saved_test_values);
    14061438        ?>
    1407        
    1408         <table class="form-table">
    1409             <tr>
    1410                 <th scope="row">
    1411                     <label><?php esc_html_e('Test Data', 'shift8-gravity-forms-sap-b1-integration'); ?></label>
    1412                 </th>
    1413                 <td>
    1414                     <table class="widefat field-mapping-table">
    1415                         <thead>
    1416                             <tr>
    1417                                 <th><?php esc_html_e('SAP Field', 'shift8-gravity-forms-sap-b1-integration'); ?></th>
    1418                                 <th><?php esc_html_e('Test Value', 'shift8-gravity-forms-sap-b1-integration'); ?></th>
    1419                             </tr>
    1420                         </thead>
    1421                         <tbody>
    1422                             <?php foreach ($sap_fields as $sap_field => $label): ?>
    1423                                 <?php $mapped_field_id = rgar($field_mapping, $sap_field); ?>
    1424                                 <?php if (!empty($mapped_field_id)): ?>
    1425                                     <tr>
    1426                                         <td><?php echo esc_html($label); ?></td>
    1427                                         <td>
    1428                                             <input type="text"
    1429                                                    name="test_values[<?php echo esc_attr($sap_field); ?>]"
    1430                                                    value="<?php echo esc_attr(rgar($default_test_values, $sap_field)); ?>"
    1431                                                    class="regular-text" />
    1432                                         </td>
    1433                                     </tr>
    1434                                 <?php endif; ?>
    1435                             <?php endforeach; ?>
    1436                         </tbody>
    1437                     </table>
    1438                     <p class="description">
    1439                         <?php esc_html_e('These test values will be sent to SAP Business One using your current field mapping configuration.', 'shift8-gravity-forms-sap-b1-integration'); ?>
    1440                         <br><strong><?php esc_html_e('Note:', 'shift8-gravity-forms-sap-b1-integration'); ?></strong>
    1441                         <?php esc_html_e('Use state codes (CA, NY) not full names, and 2-letter country codes (US, CA) to avoid SAP field length errors.', 'shift8-gravity-forms-sap-b1-integration'); ?>
    1442                     </p>
    1443                 </td>
    1444             </tr>
     1439        <table class="widefat field-mapping-table">
     1440            <thead>
     1441                <tr>
     1442                    <th><?php esc_html_e('SAP Field', 'shift8-gravity-forms-sap-b1-integration'); ?></th>
     1443                    <th><?php esc_html_e('Test Value', 'shift8-gravity-forms-sap-b1-integration'); ?></th>
     1444                </tr>
     1445            </thead>
     1446            <tbody>
     1447                <?php foreach ($sap_fields as $sap_field => $label): ?>
     1448                    <?php $mapped_field_id = rgar($field_mapping, $sap_field); ?>
     1449                    <?php if (!empty($mapped_field_id)): ?>
     1450                        <tr>
     1451                            <td><?php echo esc_html($label); ?></td>
     1452                            <td>
     1453                                <input type="text"
     1454                                       name="test_values[<?php echo esc_attr($sap_field); ?>]"
     1455                                       value="<?php echo esc_attr(rgar($test_values, $sap_field)); ?>"
     1456                                       class="regular-text" />
     1457                            </td>
     1458                        </tr>
     1459                    <?php endif; ?>
     1460                <?php endforeach; ?>
     1461            </tbody>
    14451462        </table>
     1463        <p class="description">
     1464            <?php esc_html_e('These test values will be sent to SAP Business One when you click "Test Integration" below.', 'shift8-gravity-forms-sap-b1-integration'); ?>
     1465            <br><strong><?php esc_html_e('Note:', 'shift8-gravity-forms-sap-b1-integration'); ?></strong>
     1466            <?php esc_html_e('Use SAP codes (e.g., 102 for Group, USD for Currency), state codes (CA, NY), and 2-letter country codes (US, CA).', 'shift8-gravity-forms-sap-b1-integration'); ?>
     1467        </p>
    14461468        <?php
    14471469    }
     
    14751497            'create_quotation' => rgpost('sap_create_quotation') === '1' ? '1' : '0',
    14761498            'field_mapping' => array(),
    1477             'quotation_field_mapping' => array()
     1499            'quotation_field_mapping' => array(),
     1500            'test_values' => array()
    14781501        );
     1502       
     1503        // Save test values
     1504        $test_values = rgpost('test_values');
     1505        if (is_array($test_values)) {
     1506            $allowed_fields = $this->get_allowed_sap_fields();
     1507            foreach ($test_values as $field => $value) {
     1508                if (in_array($field, $allowed_fields, true)) {
     1509                    if ($field === 'EmailAddress' || strpos($field, 'E_Mail') !== false) {
     1510                        $settings['test_values'][$field] = sanitize_email($value);
     1511                    } else {
     1512                        $settings['test_values'][$field] = sanitize_text_field($value);
     1513                    }
     1514                }
     1515            }
     1516        }
    14791517       
    14801518        // Validate and sanitize Business Partner field mapping
Note: See TracChangeset for help on using the changeset viewer.