• Resolved StephenEquus

    (@stephenequus)


    So this is an odd issue. We have a form we use for users to sign up for a free trial of our product. It’s a Salesforce form that is submitted to two places – the mysql database and to a portal that directs the form along to Salesforce.

    On WordPress pages where we use Page Templates > Template > Free Trial – the form works as expected. I’ve created shortcode for the form so we can reuse the form on other pages – anywhere I’ve tried the shortcode – the form loads but fails to submit properly. Every time I test it the page shows this error:

    Fatal error: Call to a member function insert() on null in PATH-TO-FORM-PHP-FILE on line 56.

    Here is the shortcode created in functions.php:

    function free_trial() {
    ob_start();
    include dirname( __FILE__ ) . ‘/salesforce/content-free-trial.php’;
    return ob_get_clean();
    }
    add_shortcode( ‘free_trial’, ‘free_trial’ );

    And here is Line 56 of the form php:

    $wpdb->insert( $table_name, array(
    // removing DB table info
    ) );

    Any ideas why the form pulled in via shorcode is not working? We have other Salesforce forms we use – with shortcodes – and they are working fine – but they aren’t sent to mysql DB or through a portal to Salesforce – they just go directly there.

    • This topic was modified 8 years, 4 months ago by StephenEquus.
    • This topic was modified 8 years, 4 months ago by StephenEquus.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • anonymized-15380454

    (@anonymized-15380454)

    Maybe because you forgot to add global $wpdb;; e.g.:

    function free_trial() {
    global $wpdb; // accesses the global WordPress database class instance
    ob_start();
    include dirname( __FILE__ ) . ‘/salesforce/content-free-trial.php’;
    return ob_get_clean();
    }
    add_shortcode( ‘free_trial’, ‘free_trial’ );
    Thread Starter StephenEquus

    (@stephenequus)

    Sally,

    I think that was the problem. The form done through the shortcode now works now as well does the one added through Page Templates. Fixed.

    anonymized-15380454

    (@anonymized-15380454)

    Ok. 👍🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘A problem with forms and shortcodes’ is closed to new replies.