PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

How do I get the IDs of all (active) forms

  1. sascha
    Member

    Hi there,

    I would like to achieve 2 things:
    1. get the IDs of all forms into an array
    2. get the IDs of all active forms into an array

    Could you help me achieve this? Thanks!

    Posted 12 years ago on Tuesday January 17, 2012 | Permalink
  2. Hi, Sascha,

    You can take a look at the Gravity Forms' function "get_forms" located in forms_model.php. This function gets all the forms in the database and you can pass a parameter to it (0 or 1) indicating whether you want to get the active (1) or inactive (0) forms. If you leave off the parameter, all forms will be returned. You could use it like the code below:

    //get all forms
    $myforms = RGFormsModel::get_forms();
    foreach ($myforms as $myform) {
        //loop through the forms and write out form title and status, 0 = inactive, 1 = active
        echo "Title: " . $myform->title . " Active: " . $myform ->is_active . "<br>";
    }

    Let me know if you have any questions.

    Posted 12 years ago on Wednesday February 1, 2012 | Permalink
  3. sascha
    Member

    Hi Dana,
    thanks for this. That will help me along!
    What does this syntax (RGFormsModel::get_forms();) with the colons and the RGFormsModel actually mean/do? Why can I not just call get_forms(); ?

    Posted 12 years ago on Wednesday February 1, 2012 | Permalink
  4. You won't be able to just call get_forms. The "RGFormsModel::get_forms()" tells the code to run the function get_forms() that exists within the RGFormsModel class. That class exists in forms_model.php . There could be other plugins with a function named get_forms, using this syntax you tell the code to use Gravity Forms' function.

    Posted 12 years ago on Thursday February 2, 2012 | Permalink
  5. sascha
    Member

    Thanks for explaining this!

    Posted 12 years ago on Saturday February 4, 2012 | Permalink

This topic has been resolved and has been closed to new replies.