WordPress.org

Forums

Using jQuery .load() function with wordpress and gravity forms (3 posts)

  1. adrianlittee
    Member
    Posted 1 year ago #

    I am developing a series of pages which will integrate with Gravity Forms.

    I'm using jQuery to send data to a div from a page I have created.

    Requesting Page

    <a href="#" onclick="showEntry(\''.$url.'\')">View</a>
    <div id="viewEntry"></div>

    Javascript/jQuery page

    function showEntry(url){
        jQuery(document).ready(function($){
            $('#viewEntry').load(url);
        });
    }

    PHP data page - entry.php

    $form_id = $_GET['f'];
    $form = GFFormsModel::get_form_meta( $form_id );
    
    var_dump($form);

    When ever I click run I get an error in my log file saying: PHP Fatal error: Class 'GFFormsModel' not found in

    I want to know how I can get the entry.php file recognizing all the classes in the rest of my WordPress file system.

    Any help would be great!

  2. Simalam
    Member
    Posted 1 year ago #

    You can use the following code at the top of your PHP file to have access to WordPress classes

    include_once('path/to/wp-load.php' );

    You'll have to change the path to actually point to where the wp-load.php file is actually located on your system.

  3. bcworkz
    Member
    Posted 1 year ago #

    Simalam is correct, and this will work fine for your own site where you know where your files are. If you want others to use your plugins on their sites, it's not possible to reliably know where wp-load.php lies on any random installation.

    The only way for a php file to access WP resources and plugins on any system is to make it a page template where the code is invoked by requesting a page published based on the template.

    There are a couple other ways to get requested PHP code to access WP resources. The code needs to be configured as an action callback in a plugin. That action is then triggered by sending requests either through wp-admin/admin-ajax.php or admin-post.php. The first requires an AJAX request from jQuery, the latter accepts both GET and POST requests, no jQuery required.

Topic Closed

This topic has been closed to new replies.

About this Topic