FMProxy HTML Form Example

I talked to Russ Kohn today, and he is working on a project using FMProxy. Interestingly, he’s re-tooling it to be used with javascript, which kind of proves the point that FMProxy is not a Flex-only solution. He had some feedback in terms of making better basic examples to help developers get up to speed faster and unleash the power of FMProxy. So here is I what I put together to make it a bit easier to initially set up and debug your proxy. It’s an HTML form, similar to the one included in the original whitepaper, for submitting simple POST requests, and a very simple proxy.php example that is a bit more useful than the straight passthrough example and a bit simpler than the login example (both shown as examples in the original whitepaper). See the FMProxy link above, or the direct link to the zip further down in this post if you want to checkout the original whitepaper.

index.html

First, here’s a very simple HTML form with an two choices for submission. Depending which button you click for submit, the example proxy script (below) will return a different format.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html  xml_lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Proxy Test</title>
  <meta name="generator" content="BBEdit 8.7" />
</head>
<body>
  <form action="proxy.php" method="post" id="fmproxyform">
    <fieldset>
      Host <input name="Host" type="text" value="localhost" size="100" /><br /><br />
      CommandString <input name="CommandString" type="text" value="-db=FMServer_Sample&-lay=English_List_View&-findall" size="100" /><br /><br />
      Port <input name="Port" type="text" value="80"/><br /><br />
      Username <input name="Username" type="text" value="admin"/><br /><br />
      Password <input name="Password" type="password" /><br /><br />

      <button type="submit" name="output" value="xml">Submit It</button>
      <button type="submit" name="output" value="debug">Debug</button>
    </fieldset>
  </form>
</body>
</html>

proxy.php

If the proxy sees you’re doing debug, it dumps out a print_r of the object, and if it sees it’s a normal submit, it returns the normal xml result.

<?

// jsmall 2009-04-21
// Example proxy script demonstrating a basic use case with v0.2

require_once('FMProxy.php');

$rawProxy = new FMProxyRequest();

// switch the assignment of $myProxy between these two options and compare the results:
$myProxy = $rawProxy; // use exactly what is submitted
// $myProxy = overrideForm($rawProxy); // manipulated by the override function below

$myProxy->execute();

if ($_POST['output'] == 'debug' ){
header ("content-type: text/html");
echo '<pre>';
print_r($myProxy);
echo '</pre>';
} else {
header ("content-type: text/xml");
echo $myProxy->result;
}

function overrideForm($proxyInstance){
// note how we can filter any commands we want to restrict using unset()
unset ($proxyInstance->commandArray['-findall']);
// note how we can add any commands we like to the commandArray
$proxyInstance->commandArray[urlencode('Cover Photo Credit')] = 'Barb';
$proxyInstance->commandArray['-find'] = null;
return $proxyInstance;
}

These examples will work with a machine running FMServer_Sample.fp7 file on FileMaker Server and PHP on localhost. You can modify that easily enough to fit your environment. FMServer_Sample.fp7 has an Admin account with a blank password by default. You will also need version 0.2 of FMProxy. You can download a FMProxy_0v2.zip with the example files above. Raw Output This is what the FMProxy instance contains without having overridden it. Notice the command array contains only those elements we submitted via our command string.

<pre>FMProxyRequest Object
(
    [host] => localhost
    [protocol] => http
    [port] => 80
    [fmiUri] => /fmi/xml/fmresultset.xml
    [username] => admin
    [password] =>
    [commandString:private] => -db=FMServer_Sample&-lay=English_List_View&-findall
    [commandArray] => Array
        (
            [-db] => FMServer_Sample
            [-lay] => English_List_View
            [-findall] =>
        )

    [proxyConfigArray] => Array
        (
        )

    [proxyParamsArray] => Array
        (
        )

    [result] => <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE fmresultset PUBLIC "-//FMI//DTD fmresultset//EN" "http://localhost:80/fmi/xml/fmresultset.dtd"><fmresultset >"http://www.filemaker.com/xml/fmresultset" version="1.0"><error code="0"></error><product build="10/31/2008" name="FileMaker Web Publishing Engine" version="10.0.1.59"/><datasource database="FMServer_Sample" date-format="MM/dd/yyyy" layout="English_List_View" table="ENGLISH_NATURE" time-format="HH:mm:ss" timestamp-format="MM/dd/yyyy HH:mm:ss" total-count="13"/><metadata><field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="Title" not-empty="no" numeric-only="no" result="text" time-of-day="no" type="normal"/><field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="Cover Photo Credit" not-empty="no" numeric-only="no" result="text" time-of-day="no" type="normal"/><field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="Quantity in Stock" not-empty="no" numeric-only="no" result="number" time-of-day="no" type="normal"/></metadata><resultset count="13" fetch-size="13"><record mod-id="1" record-id="1"><field name="Title"><data>Alaska 24/7</data></field><field name="Cover Photo Credit"><data>Evan R. Steinhauser, Anchorage Daily News</data></field><field name="Quantity in Stock"><data>50</data></field></record><record mod-id="2" record-id="2"><field name="Title"><data>America 24/7</data></field><field name="Cover Photo Credit"><data>Dan White</data></field><field name="Quantity in Stock"><data>200</data></field></record><record mod-id="0" record-id="3"><field name="Title"><data>Arizona 24/7</data></field><field name="Cover Photo Credit"><data>Michael Chow, The Arizona Republic</data></field><field name="Quantity in Stock"><data>0</data></field></record><record mod-id="1" record-id="4"><field name="Title"><data>California 24/7</data></field><field name="Cover Photo Credit"><data>Michael Grecco</data></field><field name="Quantity in Stock"><data>100</data></field></record><record mod-id="0" record-id="5"><field name="Title"><data>Colorado 24/7</data></field><field name="Cover Photo Credit"><data>Jeffrey Aaronson, Network Aspen</data></field><field name="Quantity in Stock"><data>0</data></field></record><record mod-id="0" record-id="6"><field name="Title"><data>Florida 24/7</data></field><field name="Cover Photo Credit"><data>Andrew Kaufman, Contact Press Images</data></field><field name="Quantity in Stock"><data>0</data></field></record><record mod-id="1" record-id="7"><field name="Title"><data>Hawaii 24/7</data></field><field name="Cover Photo Credit"><data>Richard A. Cooke III</data></field><field name="Quantity in Stock"><data>50</data></field></record><record mod-id="2" record-id="8"><field name="Title"><data>Idaho 24/7</data></field><field name="Cover Photo Credit"><data>Chad Case, Idaho Stock Images</data></field><field name="Quantity in Stock"><data>200</data></field></record><record mod-id="2" record-id="9"><field name="Title"><data>New York 24/7</data></field><field name="Cover Photo Credit"><data>Michael Groll</data></field><field name="Quantity in Stock"><data>0</data></field></record><record mod-id="2" record-id="10"><field name="Title"><data>Pennsylvania 24/7</data></field><field name="Cover Photo Credit"><data>Jason Cohn, www.jasoncohn.com</data></field><field name="Quantity in Stock"><data>50</data></field></record><record mod-id="2" record-id="11"><field name="Title"><data>Texas 24/7</data></field><field name="Cover Photo Credit"><data>Barbara Davidson, The Dallas Morning News</data></field><field name="Quantity in Stock"><data>50</data></field></record><record mod-id="2" record-id="12"><field name="Title"><data>Washington 24/7</data></field><field name="Cover Photo Credit"><data>Nathan P. Myhrvold</data></field><field name="Quantity in Stock"><data>100</data></field></record><record mod-id="0" record-id="13"><field name="Title"><data>My Book</data></field><field name="Cover Photo Credit"><data>Jeremiah</data></field><field name="Quantity in Stock"><data></data></field></record></resultset></fmresultset>
)
</pre>

Override Output

In this case we passed our FMProxy instance through the override function. Notice the command array no longer contains the -findall we submitted via our command string, and now it has a field reference being set with the value Barb and the command is -find instead. Notice in the result array here, there is only one record, in contrast with the 13 above. Tip: Do a find for resultset count on this page to quickly jump to the record count in the XML result strings.

<pre>FMProxyRequest Object
(
    [host] => localhost
    [protocol] => http
    [port] => 80
    [fmiUri] => /fmi/xml/fmresultset.xml
    [username] => admin
    [password] =>
    [commandString:private] => -db=FMServer_Sample&-lay=English_List_View&Cover+Photo+Credit=Barb&-find
    [commandArray] => Array
        (
            [-db] => FMServer_Sample
            [-lay] => English_List_View
            [Cover+Photo+Credit] => Barb
            [-find] =>
        )

    [proxyConfigArray] => Array
        (
        )

    [proxyParamsArray] => Array
        (
        )

    [result] => <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE fmresultset PUBLIC "-//FMI//DTD fmresultset//EN" "http://localhost:80/fmi/xml/fmresultset.dtd"><fmresultset >"http://www.filemaker.com/xml/fmresultset" version="1.0"><error code="0"></error><product build="10/31/2008" name="FileMaker Web Publishing Engine" version="10.0.1.59"/><datasource database="FMServer_Sample" date-format="MM/dd/yyyy" layout="English_List_View" table="ENGLISH_NATURE" time-format="HH:mm:ss" timestamp-format="MM/dd/yyyy HH:mm:ss" total-count="13"/><metadata><field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="Title" not-empty="no" numeric-only="no" result="text" time-of-day="no" type="normal"/><field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="Cover Photo Credit" not-empty="no" numeric-only="no" result="text" time-of-day="no" type="normal"/><field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="Quantity in Stock" not-empty="no" numeric-only="no" result="number" time-of-day="no" type="normal"/></metadata><resultset count="1" fetch-size="1"><record mod-id="2" record-id="11"><field name="Title"><data>Texas 24/7</data></field><field name="Cover Photo Credit"><data>Barbara Davidson, The Dallas Morning News</data></field><field name="Quantity in Stock"><data>50</data></field></record></resultset></fmresultset>
)
</pre>

Conclusion

Hopefully this offers a better illustration of the power of FMProxy. As I mention in the original whitepaper, one could imagine setting up one’s proxy such that it disallows all API commands that you don’t need by simpy unsetting them before calling execute().

2 thoughts on “FMProxy HTML Form Example”

  1. I have done a bit of research to see what, if anything, has been done with flexfm in the last two years. Seems like this project has gone dead. Is this true? Has anyone else been doing anything to bridge filemaker server and flex?

    Just wondered. It would be helpful for those who are spending time trying to sort through all this to get some kind of update on what the status is with this project. It does seem like such a good idea.

  2. ItΓÇÖs good to see this information in your post, i was looking the same but there was not any proper resource, thanx now i have the link which i was looking for my research…

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top