Subscribe
Blog

Automatically Populate Contracts and Agreements from PHP

Formstack
August 23, 2016
|
Min Read

Creating contracts and collecting signatures can be a very time-consuming task – especially if you’re running a web app with a lot of new customers coming on board.  Being able to automatically generate contracts and send them out for signature can be a crucial piece of your sales cycle.

With Formstack Documents, you can automatically populate contracts, quotes, invoices, and more from templates with a few lines of code.  You don’t have to worry about building any PDF libraries or hassling the tech team to make changes.

In this example, we’re going to show you how you can use Formstack Documents to automatically generate a contract from a PHP web app and then send the contract over to DocuSign for signature.
To get started, we’re going to setup the template for our contract using a Word document.  Inside Word, we’re going to add our boilerplate terms, and then for the spots that we want to insert our customer’s information, we’re going to use merge fields like {$FirstName}, {$LastName}, etc.

Here’s what our contract looked like:


Since we’ll be collecting signatures via DocuSign, we also need to insert a signature tag in the template so that DocuSign knows where to embed the signature once it has been signed.  This signature tag is just like any other text in our document and looks like:  \s1\



Once we have our template finished, we need to upload it to Formstack Documents.  From the Documents page in Formstack Documents, click the New Document button and enter a name.  On the next step, choose Office Document as the document type and then pick the file from your computer.



After you have uploaded your template, you’ll be taken to the settings tab where you can modify various options like the type of file that is generated and the name of the file.  For this example, we’re going to generate a PDF and include the name of our customer in the file name.



Once you have updated the settings, we’re going to setup the delivery of our document to DocuSign so that it is automatically sent to our customer for signing.  Under the Deliver tab, click the New Delivery button and pick DocuSign from the list.

After you authenticate your DocuSign account, you’ll need to define the signer’s name and email address using merge fields.  If you don’t have these merge fields in your document, choose <> from the dropdown and then enter something like {$Email}.



Once you have the DocuSign delivery setup, we’re ready to integrate this document with our PHP app.  To send data over to Formstack Documents, we’re going to do an HTTP POST request (via cURL) to the document’s Merge URL.  To find the Merge URL for your document, go to the Merge tab.



Inside our PHP code, we’re going to setup our cURL request and we’re going to send our data over as JSON.   Here’s an example for you to use:

Once you have added the cURL call to your PHP code, go ahead and run a test from your app to make sure everything is working correctly.  When you run the test, it will generate the contract and send it over to DocuSign for signature.

Here’s what our contract looked like ready to sign in DocuSign:



Start a free trial today to see how Formstack Documents can simplify your paperwork processes.

Blog

Automate Your Processes with Form to Form Prefill

Check out this step-by-step video demo on creating a form to form prefill process to automate like PTO approvals.
Read more
Formstack
Formstack is a SaaS company with a mission to help organizations digitize what matters, automate workflows, and fix processes—all without code. A variety of team members come together to compile posts under Formstack's authorship.
More Articles

Please accept the cookie consent in order to use this chat.

drift bot
1