Topic: PHP: Get all forms – WS Form

My Account

Forums

Forums General PHP: Get all forms

Viewing 1 reply thread
  • Author
    Posts
    • #29929
      cubetech
      Participant

      I needed to have a list of all (published) forms. I ended up with the following function.
      It simply returns an array where the key is the formId while value is the form label.

      Anyone has a better way to do this?

      
      function GetForms($onlyPublished = true) {
        // init vars
        $result = false;
        $join = '';
        $where = '';
      	
        // create where statement based on publish state
        if ($onlyPublished) {
          $where = "status = 'publish'";
        }
      
        // get forms
        $wsForm = new \WS_Form_Form($join, $where);
        $forms = $wsForm->db_read_all();
      
        // create array based on forms
        if (is_array($forms)) {
          foreach ($forms as $form) {
            $result[$form['id']] = $form['label'];
          }
        }
        return $result;
      }
      
    • #30031
      Mark Westguard
      Keymaster

      You can use the following function:

      $forms = wsf_form_get_all(published = false, order_by = 'label')

      e.g.

      $forms = wsf_form_get_all(true)

Viewing 1 reply thread
  • You must be logged in to reply to this topic.

Login