In this article, we will be looking at how to work with the Formstack’s REST API v2. We will be using the fstackapi_php PHP package that I built to simplify the process.
Formstack is an online form building platform. Formstack API is organised around objects that are involved in form creation and submission.
A user logs into the platform, create a Form that has Fields for collecting data and share the link to the form with the target audience that can access the Form, fill in their data and make a final submission.
Visit fstackapi_php repo on Github and follow the instructions to install and configure the package
Get the id of the form you want data to be submitted to. We can do this by:
First, getting all the forms that are available to our account and taking note of the particular form id we are interested in. It is advisable to save the returned values in a file for reference sake:
//get all forms available and take note of their ids $fsForm = new FSForm(); $allForms = $fsForm->all();
Then, let’s get the id of the fields that are associated with the form. The way Formstack works is that each Form has associated Fields; and each Field is an object with id, name, label and other attributes.
We have the formId from the snippet above. So let’s get the Fields for the form:
$fsField = new FSField(); $allFields = $fsField->all($formId);
It is also advisable that we save the returned ids for use later.
Now that we have the formId, and id of the fields. Let’s construct a data and submit it to the Form via the library.
Let’s assume our form has only two fields: name (id = “123433”) and email (id = “4312232”).
Note here, that the format for specifying the field is field_$fieldId. Where $fieldId is the id of a particular field. If the prefix 'field_' is omitted, the form submission will not reflect in Formstack’s database:
$formId = "4455455"; $data [ "field_123433" => "Demo Name", "field_4312232" => "email@example.com" ]; $fsSubmission = new FSSubmission(); $submission = $fsSubmission->newSubmission($formId, $data);
And that’s it — very simple, right? Yeah! The fstackapi_php library makes the process seamless.
What if we want to get all the submissions? Well, we only need to call this method:
$allSubmissions = $fsSubmission->all($formId);
and this method will get the detail of a single submission:
$detail = $fsSubmission->get($submissionId);
There are other methods and classes that enable you to work with folders, fields, forms and submissions. They are well documented in the Github repo of fstackapi_php.
I will encourage you to go there, read it and give it a star.
There is a chance you may not be working with Formstack API as at present. So, I will encourage you to click the social sharing buttons below and recommend this to others, in your network - who might need them now.
If you find this post helpful, learnt anything at all, just share it with your friends on Facebook and Twitter. Be proud of the quality content you read, especially in these days of junk everywhere
Maven Central to the World, deploy your open-source Java library for other people to use in their projects as a dependency
Being able to read log files on a production server can boost the quality of your emergency readiness and response. Read on to learn how.
Why upload the file, when all you need is the data in it? Cleaner, faster avoid connection timeouts, corrupted data just by adding excel_uploader js
Export your MySQL database to a zip file, send the generated SQL dump to your email, Amazon S3, Google Drive etc. Plus automate the process #DevOps
Here is a curation of the different technologies that power the web and the ones you should learn to make a living as a web developer
Ever wish there is a way you insert default data into the database during application startup in a SpringBoot environment? Read on!
We'll build a complete desktop application that'll translate English text to Morse Code and vice-versa plus an overview of Java GUI
This is a recap of how I moved from Laragon 2 to v3, my mistakes and how you can avoid them. Plus undocumented changes I discovered