Recently tasked with creating a web form allowing for potential customers to sign up over the web for a trial copy of a Filemaker/Claris app. It is a fairly tricky process. The process takes the user’s details via a typical signup form written in PHP, logs the info, creates and deploy’s the demo then emails the user with a unique URL to via using either FM-desktop or via webdirect.

Step 1: Create the form

Typically, a standard bootstrap-based form, that submit’s back to itself to deal with the POST request:

I chose to host the page by adding a virtual directory under the standard FM IIS config, and using it’s inbuilt (but heavily stripped out) version of PHP5.6. Obviously this has drawbacks, namely the lack of PDO drivers – but since it is a simple proof of concept, CSV will do. Setting up separate versions of PHP, domains, IIS config’s is out of scope of my requirements, using the inbuilt FM approach is much more limiting, but more novice users can simply drop php files in, and they will run.

Step 2: Generate a unique demo-id and create a copy of the Master FM File

Give the demo file a unique ID, the users will use this to connect directly to the file and not conflict with other happy demo-goers.

define('DEMO_FOLDER', 'C:\Program Files\FileMaker\FileMaker Server\Data\Databases...');
  
define('DEMO_FILE', 'C:\Program Files\FileMaker\FileMaker Server\Data\Databases\Master\my_master_file.fmp12');    

$uuid = uniqid();
$filename = 'demo_'.$uuid.'.fmp12';
copy(DEMO_FILE, DEMO_FOLDER.DIRECTORY_SEPARATOR.$filename);

Step 3: Create a .bat file to deploy the demo

This will create a batch file ready to be executed. The bonus point of doing it this way is that to write a tiny file is instantaneous in PHP. The drawback is that it’s more complex, I tried for a couple of hours to execute the fm-server commands directly from PHP (exec/shell_exec/etc) – using the inbuilt 5.6, and a fresh installation of php 7.2. Any successful call to the FM command set would consume all 16GB of memory and be stuck in an infinite loop – if anyone has encountered this please let me know the solution, for now it rendered the FM command’s via php completely useless. To batch files it was. (non-fm cmd commands were running normally using php functions)

The bat file below will create a file and embed the previously copied demo filename to be opened in FM Server. The batch file will then delete itself to prevent later duplicate calls to get FM server to open the file over and over.

$bat = fopen('C:/demobatches/batches/'.$filename.'.bat', 'a');
fwrite($bat, "cd C:\demoform
   START /B fmsadmin open ".$filename." -y -u <fm admin username> -p <fm admin password>
   DEL \"%~f0\"
   EXIT
");
fclose($bat);/

Step 4: Log the customer details

Dump the form data into a CSV – ideally you would implement a captcha and a more elegant storage solution, but here it wasn’t necessary. You could even make direct calls to a marketing CRM like FLG360 to follow up with the demo user at a later date – if you were feeling creative.

$data = array($filename, $_POST['inputFirstName'], $_POST['inputLastName'], $_POST['inputEmail']);

$fp = fopen('signups.csv', 'a');
fputcsv($fp, $data);
fclose($fp);

Step 5: Email the customer

Here I used PHPMailer to deal with simple email generation. You can implement this using any flavor of email you prefer. Basically a bunch of boilerplate email content, the url/demo filename to be accessed by the user.

Step 6: Create a master .bat file, to run any pending demo creations

The batch file below will run over any of the existing batch files created above and execure them. Put it in task scheduler to run every couple of minutes.

cd C:\demobatches
for /r %%i in (*) do (
	call %%i
)
exit

NB: the solution I came up with is for windows based servers, I used 2016R2. If you were using a Mac server (quite common in the FM community) then it would be slightly different and you’d need to convert the BAT files to their Bash equivalents.