FileMaker and PHP: Link to A Record Using Redirect

Let’s Learn How We Can Link to A Record Using Redirect

In this article we’ll look at how you can link to a record using redirect with FileMaker and PHP.

In later versions of FileMaker we have Snapshot Links. When you work in a database you can always give someone a Project number when you need to refer to a Project. Or we can script generating a Snapshot Link. The problem with the Snapshot link is that you’ll have to remove it once you spit it out to the Desktop. AppleScript can help with that.

Another method is the fmpURL protocol. You can generate nice links such as this:

fmp://localhost.com/SomeDB.fmp12?script=open_project_link&param=PROJECTID

Then if you copy and paste this into apps it’ll open the database. If you’re on a Mac and use Messages or email this is great!

But then I ran into a problem where my client’s law firm relies on Gmail for their primary communication AND they are using it from a web browser. Now, Gmail DOT NOT know what to do with the FMP protocol so it just breaks the URL and funky things happen. I’m sure Gmail is not the only party here that does not know what to do with it.

So one—fairly simple method—of tackling the problem is referring to good old, creating a link to a record in FileMaker with PHP. I know, this is not a novel method but when I was looking for it I couldn’t find a comprehensive article on how to achieve what I want.

What you need:

  1. A web server
  2. A PHP file
  3. A script in FM that will know what to do with the parameter it receives
  4. A button on the layout to run another script to generate the appropriate link to call your redirect PHP

Any web server anywhere will do. You just need to place a very simple redirect PHP file on it. Name it “redirect.php and place it in the appropriate document folder of the web server. Make sure the file has the proper (read, execute) permissions.

The PHP file:

<?php

//gets the query string for the value of ‘project’
$project=$_GET[‘project’];
//concats url with ID from query string.
$url = “fmp://YOUR_FM_SERVER/Database.fmp12?script=SOME_SCRIPT&param=” . $project;
//redirects to new page.
header(“Location: ” . $url);
?>

The FileMaker Scripts

  1.  You need a simple script that the PHP file will call. It will need to define the received parameter and perhaps search for the aforementioned project by ID. Obviously the script can do more, depending on your business process.
  2. And the script that calls your redirect.php on the webserver. It should generate and copy your link to the clipboard:

    https://YOUR_WEB_SERVER/redirect.php?project=PROJECTID

Then that link can be pasted anywhere and will be clickable.
6 replies
  1. Chris says:

    Thanks Agnes for posting this! Has just solved the problem for me though I had to get a web developer to do the php as I was having problems with it (I am wondering if my problems were permissions problems). Anyway. All working. THANKS.

  2. Joshua J. Brock says:

    Thanks for this!

    I am using FMPro Advanced 14, and one aspect of the database I’m designing for a client would need to make use of this. As I understand it, FM no longer allows passing variables directly in the URL…specifically, I’m need to direct customers to a specific record that’s been created for them to complete a customer satisfaction survey.

    The record will be created and pre-populated with data internally by my client. They would then email a customized URL link so that their customer can click the link, complete the survey and submit it. Your solution will head me down that correct path no?

    Also, we are having the folks at DataTrium host this for us so I’m curious how I’d handle the PHP files…that is, assuming I’d need them to host them for us? And as such, since each record will have a unique URL, the PHP file will be able to pass the unique parameters for each individual customer completing their survey?

    Thanks!

    Joshua

  3. Agnes Riley says:

    Hi Joshua,

    Thus method is for opening records in FileMaker Pro or Advanced. So that will not work for your client’s customers since they won’t have FileMaker Pro installed.

    What you need to do is use Web Direct and then send the client a URL to open that file and direct them to the record.

    You do not need PHP for this. But if you did, the PHP file would need to be on the same server as the FileMaker install.

      • Agnes Riley says:

        You are correct. You can use an “opener” database that performs a script. So put another database up on the server, enable webdirect on it and and email a link to that DB to the user. When that database is opened it has an on-open script step that does the operations you want and goes to the right layout on your main database. Extra parameters like auto-login, record number, etc can be set in the opener. You can either set up a different opener for each user who needs it or set up a procedure based on the login credentials.

Trackbacks & Pingbacks

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply