PHP code example of seunmatt / fstackapi_php

1. Go to this page and download the library: Download seunmatt/fstackapi_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

seunmatt / fstackapi_php example snippets


    FormStack\Providers\FSServiceProvider::class,


 namespace Config;
 
 return [
 
     "access_token"=> "your-formstack-application-access-token",
     "base_url" => "https://www.formstack.com/api/v2/"

 ];
 
 

//using a no-arg constructor for instatiation
//assumes you have provided your access_token
//and base_url in the config file


$fsForm = new FSForm();

$fsField = new FSField();

$fsSubmision = new FSSubmission();

$fsFolder = new FSFolder();

//initialization if no config file is provided

$token = "your-formstack-app-access-token";
$baseUrl = "https://www.formstack.com/api/v2/";

$fsForm = new FSForm($token, $baseUrl);

$fsField = new FSField($token, $baseUrl);

$fsSubmision = new FSSubmission($token, $baseUrl);

$fsFolder = new FSFolder($token, $baseUrl);

        
        $fsForm = new FSForm();
        
        //get all forms available to the authenticated account
        // API docs - https://developers.formstack.com/docs/form-get
        $allForms = $fsForm->all();
        
        //create a new form
        //see the docs for other params that can be sepcified in $body
        // API docs - https://developers.formstack.com/docs/form-post
        $body = ["name" => "Created by API"];
        $newForm = $fsForm->create($body);
              
        $formId = $newForm["id"];
        
        //Getting details for a single form
        // API Docs - https://developers.formstack.com/docs/form-id-get
        $detail = $fsForm->get($formId);

        //Updating the details of a form
        // API Docs - https://developers.formstack.com/docs/form-id-put
        $updatedForm = $fsForm->update($formId, ["name" => "Updated Form Name"]);
        
        //Deleting a form
        // API Docs - https://developers.formstack.com/docs/form-id-delete
        $response = $fsForm->delete($formId);


        $fsField = new FSField();

        //Getting all fields for a form
        // API Docs - https://developers.formstack.com/docs/form-id-field-get
        $allFields = $fsField->all($formId);

        //Adding a new field to a form
        //API Doc - https://developers.formstack.com/docs/form-id-field-post
        $param = ["field_type" => "text", "label" => "Dev API Created Field"];
        $field = $fsField->newField($formId, $param);

        $fieldId = $field["id"];

        //Details of a field
        //API Doc - https://developers.formstack.com/docs/field-id-get
        $fieldDetail = $fsField->get($fieldId);

        //Updating the details of a field
        //API Doc - https://developers.formstack.com/docs/field-id-put
        $param = ["field_type" => "text", "label" => "Dev API Updated"];
        $updatedField = $fsField->update($fieldId, $param);

        //Deleting API Created field
        //API Doc - https://developers.formstack.com/docs/field-id-delete
        $response = $fsField->delete($fieldId);

    
        $fsSubmission = new FSSubmission();

        //Submitting to a Form
        //note that you must prefix the field id with "field_x"
        //where x is the id of the field.
        //API Doc - https://developers.formstack.com/docs/form-id-submission-post 
        
        $data = [
            "field_0123943" => "Demo Field Value",
        ];
        $response = $fsSubmission->newSubmission($formId, $data);

        //Counting all Submissions to a Form
        //API Doc - https://developers.formstack.com/docs/form-id-submission-get
        
        $allSubmissions = $fsSubmission->all($formId);
       
       
        //Getting Details of a Single Submission entry
        //e.g. $submissionId = $allSubmissions["submissions"][0]["id"];
        //API Doc - https://developers.formstack.com/docs/submission-id-get
         
        $fsSubmission->get($submissionId);

        //Updating a Submission
        //API Doc - https://developers.formstack.com/docs/submission-id-put
        $data = [
            "field_".$fieldId => "Demo Organization Updated",
        ];
        $updatedSubmission = $fsSubmission->update($submissionId, $data);

        //Deleting a Submission
        //API Doc - https://developers.formstack.com/docs/submission-id-delete
        $fsSubmission->delete($submissionId);


    
            $fsFolder = new FSFolder();
    
            //All folders for the authenticated user
            //API Doc - https://developers.formstack.com/docs/folder-get
            $allFolders = $fsFolder->all();
    
            //create a new folder
            //API Doc - https://developers.formstack.com/docs/folder-post
            $newFolder = $fsFolder->newFolder("Dev Folder");
    
            //Details of a folder    
            //e.g. $folderId = $newFolder["id"];
            //API Doc - https://developers.formstack.com/docs/folder-id-get
            $folderDetails = $fsFolder->get($folderId);
    
            //Updating a folder details    
            //API Doc - https://developers.formstack.com/docs/folder-id-put
            $updatedFolder = $fsFolder->update($folderId, $newFolderName));
    
            //Deleting a folder
            //API Doc - https://developers.formstack.com/docs/folder-id-delete
            $delResponse = $fsFolder->delete($folderId);