Use a Server-Side Script (API) 


In this Article
Related Articles

Overview

Note: This method requires a basic understanding of programming for the web and may not work in all server environments. For FormAssembly Enterprise customers, all server side code should be capable of connecting via TLSv1.0, TLSv1.1, or TLSv1.2.

When using a server-side script, all URLs must use https:// and not http:// - Please ask our support team if you have any questions on this configuration.

If you are using the CAPTCHA or save & resume features, this is the best option for publishing for forms outside of FormAssembly.


Set Up

Using a website editor, copy & paste the following code sample for your code in the web page where you want your form to be visible. When doing this, make sure that you are editing the HTML code directly (often called "HTML view" or "code view").

Your form URL is shown on the Publish page, under the REST API section. Change the URL in the code sample below to match your form's URL. Only the last part (INSERT_FORM_ID_HERE) should be different.


Servers running PHP

<?php
//Set stream options
$context = stream_context_create(array('http' => array('ignore_errors' => true)));
if(!isset($_GET['tfa_next'])) {
$qs = ' ';
if(isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])){$qs='?'.$_SERVER['QUERY_STRING'];};
echo file_get_contents('https://app.formassembly.com/rest/forms/view/INSERT_FORM_ID_HERE'.$qs);
} else {
echo file_get_contents('https://app.formassembly.com/rest'.$_GET['tfa_next'],false,$context);
}
?>

Servers running ASP

<%
Dim objWinHttp
Dim strHTML
Set objWinHttp = Server.CreateObject('WinHttp.WinHttpRequest.5.1')
if(request.querystring('tfa_next')='') then
objWinHttp.Open 'GET', 'https://app.formassembly.com/rest/forms/view/INSERT_FORM_ID_HERE'
else
objWinHttp.Open 'GET', 'https://app.formassembly.com/rest' & request.querystring('tfa_next')
end if
objWinHttp.Send
Response.Write objWinHttp.ResponseText
Set objWinHttp = Nothing
%>

Servers running IIS/.NET

<%@ Import Namespace='System'%>
<%@ Import Namespace='System.IO' %>
<%@ Import Namespace='System.Net' %>
<%@ Import Namespace='System.Text' %>
<html>
<script language='C#' runat='server'>
void Page_Load(Object Src, EventArgs E) {
WebRequest request;
if (Request.QueryString['tfa_next'] == null) {
request = WebRequest.Create('https://app.formassembly.com/rest/forms/view/INSERT_FORM_ID_HERE');
} else {
request = WebRequest.Create('https://app.formassembly.com/rest' + Request.QueryString['tfa_next']);
}
WebResponse response = request.GetResponse ();
Stream dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader (dataStream, Encoding.UTF8);
FAForm.InnerHtml = reader.ReadToEnd ();
reader.Close ();
response.Close ();
}
</script>
<body>
<span id='FAForm' runat='server'/>
</body>
</html>

Servers running Ruby on Rails

In your controller:
def feedback
if params[:tfa_next]
url = "/rest/#{params[:tfa_next]}"
else
url = '/rest/forms/view/INSERT_FORM_ID_HERE'
end
response = Net::HTTP.get_response(URI('https://app.formassembly.com'+url))
@form_head, @form_body = response.split('<!-- FORM: BODY SECTION -->')
end
In your view:
<% content_for('head') do %>
<%= @form_head %>
<% end %>
<%= @form_body %>
In your layout:
<head>
[...]
<%= yield :head %>
</head>

Servers running Java

Download Package
com.formassembly.api.rest
Note: For FormAssembly Enterprise customers, Java 1.6.0 is not supported. All connections should occur over TLSv1.0, TLSv1.1, or TLSv1.2.

JSP Example

<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8'%>
<%@ page import='com.formassembly.api.rest.Form' %>
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title>FormAssembly REST API JAVA Example</title>
</head>
<body>
<%=Form.getHTML(INSERT_FORM_ID_HERE, request.getParameter('tfa_next') )%>
</body>
</html>

Servers running a different server-side technology

Regardless of what technology is available, if your server is capable of doing HTTP requests, you should be able to retrieve and display the form. Please refer to your server documentation or Google for more information.
 
We'd love to expand this section. If you have a working method not documented here, please email it to us at support@formassembly.com. Thank you!
Terms of Service · Privacy Policy