fms14 CWP Guide
fms14 CWP Guide
fms14 CWP Guide
Chapter 1
Introducing Custom Web Publishing 9
About the Web Publishing Engine 10
How a Web Publishing Engine request is processed 10
Custom Web Publishing with XML 11
Custom Web Publishing with PHP 11
Comparing XML to PHP 11
Reasons to choose XML 11
Reasons to choose PHP 11
Chapter 2
Preparing databases for Custom Web Publishing 13
Enabling Custom Web Publishing in a database 13
Accessing a protected database 13
Protecting your published databases 14
Web server support for Internet media types (MIME) 15
About publishing the contents of container fields on the web 15
Container field objects embedded in a database 15
Container fields with stored file references 15
Container fields with externally stored data 16
Container fields and progressive download 17
How web users view container field data 18
FileMaker scripts and Custom Web Publishing 18
Script tips and considerations 18
Script behavior in Custom Web Publishing solutions 20
Script triggers and Custom Web Publishing solutions 20
Chapter 3
About Custom Web Publishing with XML 21
Creating dynamic websites with the Web Publishing Engine 21
Key features in Custom Web Publishing with XML 21
Web publishing requirements 22
What is required to publish a database using Custom Web Publishing 22
What web users need to access a Custom Web Publishing solution 22
Connecting to the Internet or an intranet 23
Where to go from here 23
4
Chapter 4
Accessing XML data with the Web Publishing Engine 24
Using Custom Web Publishing with XML 24
Differences between the Web Publishing Engine and FileMaker Pro XML Import/Export 24
How the Web Publishing Engine generates XML data from a request 25
General process for accessing XML data from the Web Publishing Engine 26
About the URL syntax for XML data and container objects 26
About the URL syntax for XML data 26
About the URL syntax for FileMaker container objects in XML solutions 27
About URL text encoding 28
Accessing XML data via the Web Publishing Engine 28
About namespaces for FileMaker XML 29
About FileMaker database error codes 29
Retrieving the document type definitions for the FileMaker grammars 29
Using the fmresultset grammar 30
Description of elements in the fmresultset grammar 30
Example of XML data in the fmresultset grammar 32
Using other FileMaker XML grammars 33
Description of elements in the FMPXMLRESULT grammar 33
Example of XML data in the FMPXMLRESULT grammar 34
Description of elements in the FMPXMLLAYOUT grammar 35
Example of XML data in the FMPXMLLAYOUT grammar 37
About UTF-8 encoded data 38
Using FileMaker query strings to request XML data 38
Switching layouts for an XML response 40
Understanding how an XML request is processed 40
Troubleshooting XML document access 41
Chapter 5
Valid names used in XML query strings 42
About the query commands and parameters 42
Guidelines for using query commands and parameters 42
Query command parsing 43
About the syntax for a fully qualified field name 44
Using query commands with portal fields 44
About the syntax for specifying a global field 46
Query command reference 46
–dbnames (Database names) query command 46
–delete (Delete record) query command 46
–dup (Duplicate record) query command 47
–edit (Edit record) query command 47
–find, –findall, or –findany (Find records) query commands 47
–findquery (Compound find) query command 48
–layoutnames (Layout names) query command 48
–new (New record) query command 48
–scriptnames (Script names) query command 49
–view (View layout information) query command 49
5
Chapter 6
About Custom Web Publishing with PHP 60
Key features in Custom Web Publishing with PHP 60
Custom Web Publishing requirements 60
What is required to publish a database using Custom Web Publishing 60
What web users need to access a Custom Web Publishing solution 61
Connecting to the Internet or an intranet 61
Manually installing the FileMaker API for PHP 62
Where to go from here 63
Chapter 7
Overview of Custom Web Publishing with PHP 64
How the Web Publishing Engine works with PHP solutions 64
General steps for Custom Web Publishing with PHP 64
Chapter 8
Using the FileMaker API for PHP 66
Where to get additional information 66
FileMaker API for PHP Reference 66
FileMaker API for PHP support 67
Using the FileMaker class 67
FileMaker class objects 67
FileMaker command objects 67
6
Chapter 9
Staging, testing, and monitoring a site 85
Staging a Custom Web Publishing site 85
Testing a Custom Web Publishing site 86
Examples of stylesheets for testing XML output 87
Monitoring your site 87
Using the web server access and error logs 88
Using the Web Publishing Engine log 88
Using the Web Server Module error log 90
Using the Tomcat logs 90
Appendix A
Error codes for Custom Web Publishing 91
Error code numbers in XML format 91
Error code numbers for FileMaker databases 91
Index 92
Preface
About this guide
This guide assumes you are experienced with using FileMaker® Pro to create databases. You
should understand the basics of FileMaker Pro database design and the concepts of fields,
relationships, layouts, portals, and containers. For information about FileMaker Pro, see
FileMaker Pro Help.
This guide also assumes you are experienced with developing websites, especially with using
technologies like XML or PHP to integrate FileMaker data with websites and web applications.
This guide provides the following information about Custom Web Publishing with
FileMaker Server:
1 what is required to develop a Custom Web Publishing solution
1 how to publish your databases using XML
1 how to obtain XML data from databases hosted by FileMaker Server
1 how to publish your databases using PHP
1 how to use the FileMaker API for PHP to obtain data from databases hosted by
FileMaker Server
1 what web users need to access a Custom Web Publishing solution
Online Help is accessible from FileMaker Server Admin Console. Choose Help menu >
FileMaker Server Help.
Chapter 1
Introducing Custom Web Publishing
With FileMaker Server, you can publish your FileMaker database on the Internet or an intranet in
these ways.
FileMaker WebDirect: With FileMaker WebDirect, you can quickly and easily publish layouts from
a database on the web. You don’t need to install additional software—with compatible web
browser software and access to the Internet or an intranet, web users can connect to your
FileMaker WebDirect solution to view, edit, sort, or search records, if you give them access
privileges.
With FileMaker WebDirect, the host computer must be running FileMaker Server. The user
interface resembles the desktop FileMaker Pro application. The web pages and forms that the
web user interacts with are dependent on the layouts and views defined in the FileMaker Pro
database. For more information, see FileMaker WebDirect Guide.
Static publishing: If your data rarely changes, or if you don’t want users to have a live connection
to your database, you can use static publishing. With static publishing, you export data from a
FileMaker Pro database to create a web page that you can further customize with HTML. The web
page doesn’t change when information in your database changes, and users don’t connect to your
database. (With FileMaker WebDirect, the data is updated in the web browser whenever the data
is updated in the database.) For more information, see FileMaker Pro Help.
Custom Web Publishing: To integrate your FileMaker database with a custom website, use the
Custom Web Publishing technologies available with FileMaker Server. FileMaker Server, which
hosts the published databases, does not require FileMaker Pro to be installed or running for
Custom Web Publishing to be available.
With Custom Web Publishing, you can:
1 Integrate your database with another website
1 Determine how users interact with data
1 Control how data displays in web browsers
Using the FileMaker Server Web Publishing Engine for Custom Web Publishing
Products.fmp12 Customers.fmp12
1 2 3
Web Server Web Publishing
Engine
Web Web Server Module
Browser Database
Server
FM API and PHP code Web Publishing Core
6 5 4
4. The FileMaker Server sends the requested FileMaker data to the Web Publishing Engine.
5. The Web Publishing Engine converts the FileMaker data to respond to the request.
1 For PHP requests, the Web Publishing Engine responds to the API request.
1 For XML requests, the Web Publishing Engine sends XML data directly to the web server.
6. The web server sends the output to the requesting web browser or program.
Important Security is important when you publish data on the web. Review the security
guidelines in FileMaker Pro User’s Guide, available as a PDF file from
http://www.filemaker.com/documentation.
For information about getting a database ready for Custom Web Publishing, see chapter 2,
“Preparing databases for Custom Web Publishing.”
Chapter 1 | Introducing Custom Web Publishing 11
Note For information about Custom Web Publishing with XML, see chapter 3, “About Custom
Web Publishing with XML.”
1 PHP enables access to a wide variety of third-party components that you can integrate into your
solutions.
Note For information about Custom Web Publishing with PHP, see chapter 6, “About Custom
Web Publishing with PHP.”
Chapter 2
Preparing databases for Custom Web
Publishing
Before you can use Custom Web Publishing with a database, you must prepare the database and
protect it from unauthorized access.
1. In FileMaker Pro, open the database you want to publish using an account that has the Full
Access privilege set. Alternatively, you can open the database using an account that has the
Manage Extended Privileges access privileges.
2. Assign the Custom Web Publishing extended privilege that you want to use:
1 For Custom Web Publishing with XML, use fmxml
1 For Custom Web Publishing with PHP, use fmphp
3. Assign the privilege set(s) that include the Custom Web Publishing extended privilege to one
or more accounts, or to the Admin or Guest account.
Note When defining account names and passwords for Custom Web Publishing solutions, use
printable ASCII characters, for example a-z, A-Z, and 0-9. For more secure account names and
passwords, include punctuation characters such as “!” and “%,” but do not include colons. For
information on setting up accounts, see FileMaker Pro Help.
The following list summarizes the process that occurs when a web user uses a Custom Web
Publishing solution to access a database:
1 If you have not assigned a password for an account, web users only specify the account name.
1 If the Guest account is disabled, then users will be prompted for account name and password
when they access the database. The account must have a Custom Web Publishing extended
privilege enabled.
1 If the Guest account is enabled and has a privilege set enabled that includes a Custom Web
Publishing extended privilege, all web users automatically open the database with the access
privileges assigned to the Guest account. If the Custom Web Publishing extended privilege is
assigned to the Guest account:
1 Web users are not prompted for an account name and password when opening a file.
1 All web users will automatically log in with the Guest account and assume the Guest account
privileges. You can let users change their login accounts from a web browser with the Re-
Login script step (for example, to switch from the Guest account to an account with more
privileges).
1 The default privilege set for Guest accounts provides “read-only” access. You can change
the default privileges, including Extended Privileges, for this account. See FileMaker Pro
Help.
Note By default, web users cannot modify their account password from a web browser. You can
build this feature into a database with the Change Password script step, which allows web users
to change their passwords from their browser. See FileMaker Pro Help.
FileMaker Server supports encryption for data written to disk and for data transmitted to clients.
1 Encrypt your database by using the Database Encryption feature of FileMaker Pro Advanced.
Encryption protects the FileMaker database file and any temporary files written to disk. For
more information on encrypting a database, see FileMaker Server Getting Started Guide and
FileMaker Pro Help.
1 An encrypted database that is hosted on FileMaker Server is opened by using Admin
Console or the command line interface (CLI). As the FileMaker Server administrator, you
open the file with its database encryption password, so that FileMaker clients can use the
encrypted database.
1 Once the FileMaker encrypted database is opened with the encryption password by the
FileMaker Server administrator, FileMaker clients don’t need the encryption password to
access the encrypted database. For more information about opening an encrypted
database, see FileMaker Server Help.
1 Use Secure Sockets Layer (SSL) encryption for communication between the web server and
web browsers. SSL connections are accessed through an HTTPS connection.
FileMaker Server provides a standard SSL certificate signed by FileMaker, Inc. that does not
verify the server name. The FileMaker default certificate is intended only for test purposes. A
custom SSL certificate is required for production use. See FileMaker Server Getting Started
Guide.
For more information on securing your database, see FileMaker Pro User’s Guide, available as a
PDF file from http://www.filemaker.com/documentation.
1. Store the container object files in the Web folder inside the FileMaker Pro folder.
Chapter 2 | Preparing databases for Custom Web Publishing 16
2. In FileMaker Pro, insert the objects into the container field and select the Store only a
reference to the file option.
3. Copy or move the referenced object files in the Web folder to the same relative path location in
the root folder of the web server software.
1 For IIS (Windows):
[drive]:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf
where [drive] is the drive on which the Web Publishing Engine component of your
FileMaker Server deployment resides.
1 For Apache (OS X): /Library/FileMaker Server/HTTPServer/htdocs
Note For container objects stored as file references, your web server must be configured to
support the MIME (Multipurpose Internet Mail Extensions) types for the kinds of files you want to
serve, such as movies. Your web server determines the support for the current MIME types
registered for the Internet. The Web Publishing Engine does not change a web server’s support
for MIME. For more information, see the documentation for your web server.
1. Place the database file in the proper location on the server. Place the FileMaker Pro database
files that you want FileMaker Server to open — or shortcuts (Windows) or aliases (OS X) to
those files — in the following folders:
1 Windows:
[drive]:\Program Files\FileMaker\FileMaker Server\Data\Databases\
where [drive] is the primary drive from which the system is started.
1 OS X: /Library/FileMaker Server/Data/Databases/
Or you can place the files in an optionally specified additional database folder.
2. In the folder where you placed the database, create a folder named RC_Data_FMS, if it
doesn’t already exist.
Chapter 2 | Preparing databases for Custom Web Publishing 17
3. In the RC_Data_FMS folder, create a folder with a name that matches the name of your
database. For example, if your database is named Customers, then create a folder named
Customers. Place the externally stored objects in the new folder you created.
Note When databases are hosted on FileMaker Server, there is no way for multiple databases
to share a common folder of container objects. The container objects for each database needs
to be in a folder identified by that database’s name.
4. For files that will be shared from OS X, change the files to belong to the fmsadmin group.
For more information about manually uploading databases, see FileMaker Pro Help.
1 If your scripts contain unknown steps—for example, steps that are obsolete or are not
recognized—running these script steps returns FileMaker Pro error 4 (“Command is unknown”).
Use the Allow User Abort script step to determine how subsequent steps are handled:
1 If the Allow User Abort script step option is enabled (on), unknown script steps stop the script
from continuing.
1 If Allow User Abort is disabled (off), unknown script steps are skipped and the script
continues to execute.
1 If Allow User Abort is not included, scripts are executed as if Allow User Abort were enabled,
so unknown script steps stop scripts.
1 If your scripts contain unsupported steps—for example, steps that are not web-
compatible—running these script steps returns FileMaker Pro error 3 (“Command is
unavailable”). These unsupported script steps are skipped and the script continues to execute.
In FileMaker 14, the Allow User Abort script step has no impact on the behavior of unsupported
script steps.
1 Some scripts that work with one step from a FileMaker Pro client may require an additional
Commit Record/Request script step to save the data to the host. Because web users don’t have
a direct connection to the host, they aren’t notified when data changes. For example, features
like conditional value lists aren’t as responsive for web users because the data must be saved
to the host before the effects are seen in the value list field.
1 Any script that modifies data should include the Commit Record/Request script step, because
data changes aren’t visible in the browser until the data is saved or “submitted” to the server.
This includes several script steps like Cut, Copy, and Paste. Many single-step actions should
be converted into scripts to include the Commit Record/Request step. When designing scripts
that will be executed from a web browser, include the Commit Record/Request step at the end
of a script to make sure all changes are saved.
1 To create conditional scripts based on the type of client, use the Get(ApplicationVersion)
function. If the value returned includes a “Web Publishing Engine” string, then you know that
the current user is accessing your database with Custom Web Publishing. For more information
on functions, see FileMaker Pro Help.
1 Open each script that web users might run and verify that the script will execute properly when
the database is hosted as a Custom Web Publishing solution. Check that the script uses only
script steps that are supported for Custom Web Publishing, as described above.
Chapter 2 | Preparing databases for Custom Web Publishing 20
Note For FileMaker Pro 14, to specify that you want a script performed when a file is opened,
you need to use the OnFirstWindowOpen script trigger. Similarly, to specify that you want a script
performed when a file is closed, you need to use the OnLastWindowClose script trigger.
Chapter 3
About Custom Web Publishing with XML
Creating dynamic websites with the Web Publishing Engine
The Web Publishing Engine provides Custom Web Publishing for FileMaker Server using XML
data publishing. Custom Web Publishing provides several benefits:
1 Customization: You can determine how web users interact with FileMaker data, and how the
data displays in web browsers.
1 Data interchange: By using FileMaker XML, you can exchange FileMaker data with other
websites and applications.
1 Data integration: You can integrate FileMaker data into other websites, with other middleware,
and with custom applications. You can make the data look like it belongs to another website
instead of displaying an entire FileMaker layout in the web browser.
1 Security: The FileMaker Server administrator can individually enable or disable XML web
publishing for all databases hosted by the server. As the FileMaker database owner, you can
control web user access to or XML web publishing for each database.
1 Control and filtering of published data: You can control and filter the data and the type of
database information you want to publish, which prevents unauthorized use of the database.
You can also hide metadata, such as database and field names.
1 Based on an open standard: You have more access to tools, resources and skilled personnel
for Custom Web Publishing solutions. If you know standard XML, then you can start developing
solutions after learning a few unique details about Custom Web Publishing with XML, such as
the URL syntax and query parameters to use.
Custom Web Publishing with XML allows you to retrieve data from FileMaker databases, and
easily use the data in other output formats. By using an HTTP request with the appropriate query
commands and parameters, you can retrieve FileMaker data as an XML document. You can then
use the XML data in other applications. See “Accessing XML data via the Web Publishing Engine”
on page 28.
1 You can pass a parameter value to a FileMaker script. For more information, see “–script.param
(Pass parameter to Script) query parameter” on page 56, “–script.prefind.param (Pass
parameter to Script before Find) query parameter” on page 57, and “–script.presort.param
(Pass parameter to Script before Sort) query parameter” on page 58.
1 The fmresultset XML grammar enables you to access fields by name and manipulate
relatedset (portal) data.
1 To access data in a database, you must specify a layout. See chapter 5, “Valid names used in
XML query strings,”
Note The Web Publishing Engine generates XML data that is well-formed and compliant with the
XML 1.0 specification. For details about the requirements for well-formed XML, see the XML
specification, which is available at http://www.w3.org.
Differences between the Web Publishing Engine and FileMaker Pro XML
Import/Export
The Web Publishing Engine and FileMaker Pro both enable you to use XML data with FileMaker
databases. There are, however, some important differences between the two methods:
1 For accessing XML data, the Web Publishing Engine supports the fmresultset,
FMPXMLRESULT, and FMPXMLLAYOUT grammars. For XML import, FileMaker Pro uses the
FMPXMLRESULT grammar, and for export, FileMaker Pro uses the FMPXMLRESULT grammar.
See “Accessing XML data via the Web Publishing Engine” on page 28.
1 To access XML data with the Web Publishing Engine, you use a Web Publishing Engine query
string in a URL. To import and export XML with FileMaker Pro, you use FileMaker Pro menu
commands or scripts.
1 The Web Publishing Engine is server-based and can be installed on the same or a different host
than FileMaker Server. FileMaker Pro XML import and export is desktop-based.
1 You can dynamically access XML data from FileMaker databases by using URL requests with
the Web Publishing Engine. The FileMaker Pro XML export feature generates a pre-specified
XML data file.
1 Working with XML data via the Web Publishing Engine is an interactive operation.
FileMaker Pro XML import and export is a batch operation.
Chapter 4 | Accessing XML data with the Web Publishing Engine 25
1 The Web Publishing Engine can access XML data from a FileMaker portal, but FileMaker Pro
cannot.
1 The Web Publishing Engine can access data in a container field, but FileMaker Pro cannot.
1 The Web Publishing Engine provides real-time access to FileMaker data via HTTP or HTTPS,
but FileMaker Pro cannot.
Note For information on using FileMaker Pro to import and export data in XML format, see
FileMaker Pro Help.
How the Web Publishing Engine generates XML data from a request
After a request for XML data is sent to the web server, the Web Publishing Engine queries the
FileMaker database and returns the data as an XML document.
Request for XML data is routed from web browser or program to FileMaker Database Server
Orders.fmp12 Catalog.fmp12
XML data is routed back from FileMaker Database Server to web browser or program
Web
Browser FileMaker Server Web 4. FileMaker Database
5. Web Publishing Core Publishing Engine Server sends requested
converts data to XML and data to Web Publishing
sends it to web server. Core.
6. Web server Web Publishing Core
sends output to
web browser or Web Server
program.
General process for accessing XML data from the Web Publishing Engine
Here is an overview of the process for using the Web Publishing Engine to access XML data in a
FileMaker database:
1. In the FileMaker Server Admin Console, make sure XML Publishing is enabled. See
FileMaker Server Help.
2. In FileMaker Pro, open each FileMaker database that you’re publishing and make sure the
database has the fmxml extended privilege enabled for XML Custom Web Publishing. See
“Enabling Custom Web Publishing in a database” on page 13.
To access XML data in a portal, set the view for the database layout to View as Form or View
as List. If a user or script changes the view of the database layout to View as Table, only the
first related record (first row of the portal) is accessible as XML data.
The XML data is output in an order that corresponds to the order in which field objects were
added to the layout. If you want the XML data order to match the order in which fields appear
on the screen (top-to-bottom, left-to-right order), then select all fields, group them, and then
ungroup them. This procedure resets the layout order to match the screen order.
3. Send an HTTP or HTTPS request in the form of a URL that specifies the FileMaker XML
grammar, one query command, and one or more FileMaker query parameters to the Web
Publishing Engine through an HTML form, an HREF link, or a script in your program or web
page. You can also type the URL in a web browser.
For information on specifying the URL, see the next section, “About the URL syntax for XML
data and container objects.” For information on query commands and parameters, see “Using
FileMaker query strings to request XML data” on page 38, and chapter 5, “Valid names used in
XML query strings,”
4. The Web Publishing Engine uses the grammar you specified in the URL to generate XML data
containing the results of your request, such as a set of records from the database, and returns
it to your program or web browser.
5. The web browser, if it has an XML parser, displays the data, or the program uses the data in
the way you specified.
About the URL syntax for XML data and container objects
This section describes the URL syntax for using the Web Publishing Engine to access XML data
and container objects from FileMaker databases.
1 <xml_grammar> is the name of the FileMaker XML grammar. Possible values are
fmresultset, FMPXMLRESULT, or FMPXMLLAYOUT. See “Using the fmresultset grammar” on
page 30 and “Using other FileMaker XML grammars” on page 33.
1 <query string> is a combination of one query command and one or more query parameters
for FileMaker XML publishing. (The –dbnames command doesn’t require any parameters.) See
“Using FileMaker query strings to request XML data” on page 38, and chapter 5, “Valid names
used in XML query strings.”
Note The URL syntax, including the names of the query command and parameters, is case
sensitive except for portions of the query string. The majority of the URL is in lowercase, with the
exception of the two uppercase grammar names: FMPXMLRESULT and FMPXMLLAYOUT. For
information on the rules for case sensitivity of the query string, see “Guidelines for using query
commands and parameters” on page 42.
Here are two examples of URLs for accessing XML data via the Web Publishing Engine:
http://server.company.com/fmi/xml/fmresultset.xml?-db=products&-lay=sales
&-findall
http://192.168.123.101/fmi/xml/FMPXMLRESULT.xml?-db=products&-lay=sales
&-findall
About the URL syntax for FileMaker container objects in XML solutions
In a generated XML document for an XML solution, the syntax used to refer to a container object
is different for container fields that store the actual object in the database, as opposed to container
fields that store a reference to the object.
Note In the generated XML for a container field, the value for the –field query parameter is a
fully qualified field name. The number in the parentheses indicates the repetition number for the
container field, and is generated for both repeating and non-repeating fields. See “About the
syntax for a fully qualified field name” on page 44.
To retrieve the container data from the database, use the following syntax:
<scheme>://<host>[:<port>]/fmi/xml/cnt/data.<extension>?<query string>
For information about <scheme>, <host>, or <port>, see the previous section, “About the URL
syntax for XML data.”
Chapter 4 | Accessing XML data with the Web Publishing Engine 28
For example:
http://www.company.com/fmi/xml/cnt/data.jpg?-db=products&-lay=sales
&-field=product_image(1)&-recid=2
Note The referenced container object must be stored in the FileMaker Pro Web folder when the
record is created or edited, and then copied or moved to a folder with the same relative location
in the root folder of the web server software. See “About publishing the contents of container fields
on the web” on page 15.
Depending on the grammar you specify in the URL request, the Web Publishing Engine will
generate an XML document using one of the grammars. Each XML document contains a default
XML namespace declaration for the grammar. See the next section, “About namespaces for
FileMaker XML.” Use one of these grammars in your document or web page to display and work
with FileMaker data in XML format.
Note XML data generated by the Web Publishing Engine is encoded using UTF-8 format
(Unicode Transformation Format 8). See “About UTF-8 encoded data” on page 38.
The error code element in the XML document indicates errors related to the database and query
strings. See appendix A, “Error codes for Custom Web Publishing.”
For example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees&-lay=family
&-findall
The Web Publishing Engine will generate an XML document using the fmresultset grammar.
In the XML document, the Web Publishing Engine will reference the document type definition for
the fmresultset grammar in the <!DOCTYPE> instruction in the second line of the document,
immediately after the <?xml...?> instruction. The <!DOCTYPE> instruction specifies the URL for
downloading the DTD for the fmresultset grammar.
<datasource> element
In the fmresultset grammar, the <datasource> element contains the table, layout, date-
format, time-format, timestamp-format, total-count, and database attributes.
1 The date-format attribute of the <datasource> element specifies the format of dates in the
XML document:
MM/dd/yyyy
where:
1 MM is the 2-digit value for the month (01 through 12, where 01 is January and 12 is December)
1 dd is the 2-digit value for the day of the month (01 through 31)
1 yyyy is the 4-digit value for the year
1 The time-format attribute of the <datasource> element specifies the format of times in the
XML document:
HH:mm:ss
where:
1 HH is the 2-digit value for hours (00 through 23, for the 24-hour format)
1 mm is the 2-digit value for minutes (00 through 59)
1 ss is the 2-digit value for seconds (00 through 59)
1 The timestamp-format attribute of the <datasource> element combines the formats of date-
format and time-format into one timestamp:
MM/dd/yyyy HH:mm:ss
Chapter 4 | Accessing XML data with the Web Publishing Engine 31
<metadata> element
The <metadata> element of the fmresultset grammar contains one or more <field-
definition> and <relatedset-definition> elements, each containing attributes for one
of the fields of the result set.
The <field-definition> attributes specify:
1 whether the field is an auto-enter field (“yes” or “no”)
1 whether the field is a four-digit-year field (“yes” or “no)
1 whether it is a global field (“yes” or “no”)
1 the maximum number of repeating values (max-repeat attribute)
1 the maximum number of characters allowed (max-characters attribute)
1 whether it is a not-empty field (“yes” or “no”)
1 whether it is for numeric data only (“yes” or “no”)
1 result (“text”, “number”, “date”, “time”, “timestamp”, or “container”)
1 whether it is a time-of-day field (“yes” or “no”)
1 type (“normal”, “calculation”, or “summary”)
1 and the field name (fully qualified as necessary)
<resultset> element
The <resultset> element contains the <record> elements returned as the result of a query
and an attribute for the total number of records found. Each <record> element contains the field
data for one record in the result set—including the mod-id and the record-id attributes for the
record, and the <data> element containing the data for one field in the record.
Each record in a portal is represented by a <record> element within the <relatedset>
element. The count attribute of the <relatedset> element specifies the number of records in
the portal, and the table attribute specifies the table associated with the portal.
Chapter 4 | Accessing XML data with the Web Publishing Engine 32
</field>
</record>
</resultset>
</fmresultset>
For example:
http://192.168.123.101/fmi/xml/FMPXMLRESULT.xml?-db=employees&-lay=family
&-findall
To use the FMPXMLLAYOUT grammar, specify the following grammar name with the –view query
command in the URL requesting the XML document from the Web Publishing Engine:
FMPXMLLAYOUT.xml
For example:
http://192.168.123.101/fmi/xml/FMPXMLLAYOUT.xml?-db=employees&-lay=family
&-view
Note When specifying the FMPXMLRESULT and FMPXMLLAYOUT grammars, be sure to enter the
grammar name in uppercase.
In the generated XML document, the Web Publishing Engine will reference the document type
definition for the grammar in the <!DOCTYPE> instruction in the second line of the document,
immediately after the <?xml...?> instruction. The <!DOCTYPE> instruction specifies the URL for
downloading the DTD for the grammar.
The <RESULTSET> element contains all of the <ROW> elements returned as the result of a query
and an attribute for the total number of records found. Each <ROW> element contains the
field/column data for one row in the result set. This data includes the RECORDID and MODID for
the row (see “–modid (Modification ID) query parameter” on page 53), and the <COL> element.
The <COL> element contains the data for one field/column in the row where multiple <DATA>
elements represent one of the values in a repeating or portal field.
The order of the <COL> elements corresponds with the order of the <FIELD> elements in the
<METADATA> element—for example, where the “Title” and “Artist” fields are listed in the
<METADATA> element, “Village Market” and then “Camille Pissarro” are listed in the same order
in the <RESULTSET> and <ROW> elements.
Chapter 4 | Accessing XML data with the Web Publishing Engine 35
1 If Also display values from second field and Show values only from second field are both
selected, the DISPLAY attribute contains the value in the second field only. In the following XML
data example, the DISPLAY attribute contains the art style’s name only:
<VALUELISTS>
<VALUELIST NAME="style">
<VALUE DISPLAY="Impressionism">100</VALUE>
<VALUE DISPLAY="Cubism">101</VALUE>
<VALUE DISPLAY="Abstract">102</VALUE>
</VALUELIST>
</VALUELISTS>
Chapter 4 | Accessing XML data with the Web Publishing Engine 36
1 If Also display values from second field is selected and Show values only from second
field is not selected, the DISPLAY attribute contains the values in both fields of a value list. In
the following XML data example, the DISPLAY attribute contains both the art style’s ID number
and the art style’s name:
<VALUELISTS>
<VALUELIST NAME="style">
<VALUE DISPLAY="100 Impressionism">100</VALUE>
<VALUE DISPLAY="101 Cubism">101</VALUE>
<VALUE DISPLAY="102 Abstract">102</VALUE>
</VALUELIST>
</VALUELISTS>
For date, time, and timestamp fields, data for value lists are formatted using the “fm” format for
that field type. The “fm” formats are MM/dd/yyyy for date, HH:mm:ss for time, and MM/dd/yyyy
HH:mm:ss for timestamp. For example, if a “birthdays” value list is used for a pop-up menu on a
“birthdate” field of a layout, and the “birthdate” field is of type date, then the values output for that
value list will all be in the “fm” date format.
Note If two fields with different field types on a layout share the same value list, the first field’s
type determines the format of the value list data.
Chapter 4 | Accessing XML data with the Web Publishing Engine 37
Note Be sure to use a web browser or text editor program that supports UTF-8 files.
A query string must contain only one query command, such as –new. Most query commands also
require various matching query parameters in the query string. For example, all query commands
except –dbnames require the –db parameter that specifies the database to query.
You can also use query commands and parameters in a URL.
This section contains a summary of the FileMaker query commands and parameters. For more
information about using them in a query string, see “Valid names used in XML query strings” on
page 42.
Use this query command name To execute this command
–dbnames Retrieve names of all hosted and web-shared databases.
–delete Delete record.
–dup Duplicate record.
–edit Edit record.
–find Find record(s).
–findall Find all records.
Chapter 4 | Accessing XML data with the Web Publishing Engine 39
2. Set the global field values specified in the query (the “.global=” portion of a URL).
8. Process the –lay.response query parameter to switch to a different layout, if this is specified.
9. Generate the XML document.
If one of the above steps generates an error code, the request processing stops; any steps that
follow are not executed. However, any prior steps in the request are still executed.
For example, consider a request that deletes the current record, sorts the records, and then
executes a script. If the –sortfield parameter specifies a non-existent field, the request deletes
the current record and returns error code 102 (“Field is missing”), but does not execute the script.
Chapter 4 | Accessing XML data with the Web Publishing Engine 41
Important The –lay parameter for specifying a layout is required with all query commands
except –dbnames, –layoutnames, and –scriptnames.
1 For query parameters and field names, specify the particular value you want to use, such as -
db=employees. For query commands, don’t specify an “=” sign or a value after the command
name, such as –findall.
1 The Web Publishing Engine converts all reserved words to lowercase, including query
commands, query parameters, and command values where specific values are expected (for
example: –lop=and, –lop=or, –sortorder=ascend, –sortorder=descend,
–max=all).
1 Database names, layout names, and field names used in query strings are case insensitive,
such as using –lay=mylayout to specify the layout name MyLayout.
1 It is not recommended to use periods or parentheses in field names. In some cases, field names
with periods may work, but field names with the following exceptions can never be used:
1 The period cannot be followed by a number. For example, myfield.9 is an invalid field
name.
1 The period cannot be followed by the text string op (the two letters “op”). For example,
myfield.op is an invalid field name.
1 The period cannot be followed by the text string global (the word “global”). For example,
myfield.global is an invalid field name.
Field names containing any of these exceptions cannot be accessed via XML using an HTTP
query. These constructs are reserved for record IDs, as described in the section, “About the
syntax for a fully qualified field name,” below.
1 For the –find command, the value of a field is case insensitive. For example, you can use
Field1=Blue or Field1=blue. For the –new and –edit commands, the case you use in
the value of a field is preserved and stored in the database exactly as you specify in the query
string. For example, LastName=Doe.
4. Is the query missing the required database name parameter (–db parameter)?
5. Is the query missing the required layout name parameter (–lay parameter)?
Chapter 5 | Valid names used in XML query strings 44
Note If a query contains valid but extraneous information, the query is processed without an
error. For example, if you specify the –lop parameter on a –delete command, the –lop
parameter is ignored because it does not cause the query to be invalid or ambiguous.
For information about specific error codes returned, see appendix A, “Error codes for Custom Web
Publishing.”
Note To be accessible, fields must be placed on the layout you specify in the query string.
For example, the following URL adds a new parent Employee record for John Doe, and a new
related record for Jane in the portal at the same time. The name of the related table is Dependents,
and the name of the related field in the portal is Names. The match field, ID, stores an employee
ID number.
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=family&FirstName=John&LastName=Doe&ID=9756&Dependents::Names.0=Jane&-new
Note You can only add one related record to a portal per request.
Here is an example of how to use one request to edit multiple portal records via the parent record:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees&-lay=family
&-recid=1001&Dependents::Names.2=Kevin&Dependents::Names.5=Susan&-edit
You can also use the –edit command and specify 0 as the portal record ID to add a new related
record in the portal for an existing parent record. For example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees&-lay=family
&-recid=1001&Dependents::Names.0=Timothy&-edit
But the following URL deletes a portal record with a record ID of “3” from the related table called
“Dependents”, with the parent record ID of “1001”.
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees&-lay=family
&-recid=1001&-delete.related=Dependents.3&-edit
For more information, see “–delete.related (Portal records delete) query parameter” on page 50.
Chapter 5 | Valid names used in XML query strings 46
where global identifies a field as using global storage. For information about table-name and
field-name(repetition-number), see “About the syntax for a fully qualified field name” on
page 44. For information on global fields, see FileMaker Pro Help.
You must use the .global syntax to identify a global field in a query string. The Web Publishing
Engine sets the parameter values for global fields before performing the query command or setting
any other parameter values in the query string. For direct XML requests, the global values expire
immediately after the request is made.
If you don’t use the .global syntax to identify a global field in a query string, the Web Publishing
Engine evaluates the global field along with the remainder of the query string without setting the
global field value first.
For example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees&-lay=departments
&Country.global=USA&-recid=1&-edit
Note For information on editing records in a portal, see “Editing records in a portal” on page 45.
Example:
To edit a record:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&-recid=13&Country=USA&-edit
Note Specifying a field name multiple times in a single request is not supported;
FileMaker Server parses all of the values, but uses only the last value parsed.
Note For information on including new data for a portal, see “Adding records to a portal” on
page 44.
Example:
To add a new record:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&Country=Australia&-new
Note When specifying the name of the database for the –db parameter in query strings, do not
include a filename extension. The actual database filename can optionally include an extension,
but extensions are not allowed as a value for the –db parameter.
Chapter 5 | Valid names used in XML query strings 50
Note Specifying a field name multiple times in a single request is not supported;
FileMaker Server parses all of the values, but uses only the last value parsed.
where:
1 table-name is the table that contains the field and is only required if the field is not in the
source table of the layout specified in the query string.
1 op-symbol is one of the keywords in the preceding table, such as cn.
Example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&name=Tim&name.op=cn&-find
Note The bw keyword does not work with date, time, or timestamp strings, or with the current
date (//) find operator.
Chapter 5 | Valid names used in XML query strings 52
You can use any FileMaker Pro find operator by including it as part of the search criteria instead
of specifying the fieldname.op operator keyword. For example, to find a range of values using the
range (...) find operator, do not specify any operator keyword. Instead, use the characters “...”
between the range values in the search criteria.
Example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees&
-lay=departments&IDnum=915...925&-find
For more information on the operators you can use to find text, see FileMaker Pro Help.
Example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&Last+Name=Smith&Birthdate=2/5/1972&-lop=and&-find
Chapter 5 | Valid names used in XML query strings 53
Note The –max query parameter does not affect the values returned for portal records. To limit
the number of rows returned for portal records, see “–relatedsets.max (Limit portal records) query
parameter” on page 56.
Examples:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&-max=10&-findall
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&-max=all&-findall
Where:
<request-declarations> is two or more request declarations.
1 Each request declaration is composed of one or more query identifiers separated by commas,
and enclosed in parentheses. A query identifier is the letter “q” followed by a number. For
example: q1
Chapter 5 | Valid names used in XML query strings 54
1 Enclosed in parentheses, the multiple queries act as logical AND searches that narrow the
found set. For example, (q1, q2) returns records that match q1 and q2.
Note It is not recommended to use the same fields for multiple q variables in the same “and”
search criteria.
1 As with FileMaker Pro, each request can be either a find request or an omit request. A find
request adds the matching records to the found set; an omit request removes the matching
records from the found set. The default is a find request. For an omit request, put an
exclamation point (!) in front of the opening parenthesis.
For example: (q1);!(q2)
In this example, q1 is a find request; q2 is an omit request because it is preceded by an
exclamation point.
1 Requests are separated by semicolons. Multiple find requests act as logical OR searches that
broaden the found set. For example, (q1);(q2) returns records that match q1 or q2. Omit
requests do not act as logical OR searches because omit requests remove records from the
found set.
1 Requests are executed in the order specified; the found set includes the results of the entire
compound find request.
Example 2:
http://localhost/fmi/xml/FMPXMLLAYOUT.xml?-db=test&-lay=empty&-view&-recid=9
Notes:
1 The –relatedsets.filter parameter has no impact on how portal records are sorted in
XML queries. The sort specified in FileMaker Pro is respected whether the
–relatedsets.filter parameter value is layout or none.
1 The Filter portal records setting in the Portal Setup dialog box is not supported for XML
queries. Any calculation specified for the Filter portal records setting is ignored.
Note For information on filtering portal records, see “–relatedsets.filter (Filter portal records)
query parameter” above.
Example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=departments&-script=myscript&-script.param=Smith%7CChatterjee%7CSu
&-findall
In the following example, the “dept” field is sorted first, and then the “rating” field is sorted. Both
fields are sorted in ascending order because the –sortorder query parameter is not specified.
Example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=performance&-sortfield.1=dept&-sortfield.2=rating&-findall
where:
1 precedence-number in the –sortorder.precedence-number parameter is a number
from 1 to 9 that specifies the –sortfield query parameter that the –sortorder query
parameter applies to.
1 sort-method is one of the keywords in the preceding table to specify the sort order, such as
ascend
In the following example, the sort order of the highest precedence sort field (dept) is ascend, and
the sort order of the second highest precedence sort field (rating) is descend. The precedence-
number 2 in -sortorder.2 specifies that the query parameter -sortorder.2=descend
applies to the -sortfield.2=rating query parameter.
Example:
http://192.168.123.101/fmi/xml/fmresultset.xml?-db=employees
&-lay=performance&-sortfield.1=dept&-sortorder.1=ascend&-sortfield.2=rating
&-sortorder.2=descend&-findall
Note If a –sortorder query parameter is not specified for a sort field, the default ascending sort
is used.
Chapter 6
About Custom Web Publishing with PHP
Custom Web Publishing with PHP lets you use the PHP scripting language to integrate data from
FileMaker databases with your customized web page layouts. Custom Web Publishing with PHP
provides the FileMaker API for PHP, which is a PHP class created by FileMaker that accesses
databases hosted by FileMaker Server. This PHP class connects to the FileMaker Server Web
Publishing Engine and makes data available to your web server’s PHP engine.
1 PHP installed on the web server. FileMaker Server can install the supported version of PHP, or
you can use your own version.
1 For the minimum required version of PHP, see http://www.filemaker.com/r/fms-specs.
1 For information about PHP, see http://php.net.
1 The version of PHP installed on the web server must support cURL (client URL library)
functions. For information about cURL, see http://php.net/curl.
Important When you install the FileMaker Server supported version of PHP, it does not show
up in the OS X Server Admin tool; it is not supposed to be listed. If you use the OS X Server
Admin tool to turn on PHP, you disable the FileMaker Server supported version of PHP, and
enable your own version of PHP.
Note For the minimum required version of PHP, see http://www.filemaker.com/r/fms-specs. For
best results, use the appropriate version of PHP.
To make the FileMaker API for PHP accessible to your PHP scripts
When you installed FileMaker Server, the FileMaker API for PHP package was included as a .zip
file in the following location:
1 For IIS (Windows):
[drive]:\Program Files\FileMaker\FileMaker Server\Web
Publishing\FM_API_for_PHP_Standalone.zip
where [drive] is the drive on which the web server component of your FileMaker Server
deployment resides.
1 For Apache (OS X):
/Library/FileMaker Server/Web Publishing/FM_API_for_PHP_Standalone.zip
The FM_API_for_PHP_Standalone.zip file contains a file called FileMaker.php and a folder called
FileMaker. Unzip the file and copy the FileMaker.php file and the FileMaker folder to either of these
locations:
1 the folder where your PHP scripts reside.
1 For IIS (Windows) through HTTP or HTTPS:
[drive]:\Program Files\FileMaker\FileMaker Server\HTTPServer\Conf
where [drive] is the drive on which the Web Publishing Engine component of your
FileMaker Server deployment resides.
1 For Apache (OS X) through HTTP:
/Library/FileMaker Server/HTTPServer/htdocs
1 For Apache (OS X) through HTTPS:
/Library/FileMaker Server/HTTPServer/htdocs/httpsRoot
1 one of the include_path directories in your PHP installation. The default location for OS X is
/usr/lib/php.
Chapter 6 | About Custom Web Publishing with PHP 63
1. In Admin Console, make sure Enable PHP publishing is selected. See FileMaker Server
Getting Started Guide.
2. In Admin Console, choose the Databases pane and make sure each FileMaker database that
you’re publishing has the fmphp extended privilege enabled for Custom Web Publishing with
PHP.
If necessary, use FileMaker Pro to enable Custom Web Publishing for a database. See
chapter 2, “Preparing databases for Custom Web Publishing.”
Note Make sure that you use equivalent FileMaker database privilege sets when developing
PHP solutions that will be given to the end user. Otherwise, you may have access to layouts
and features in the FileMaker database that will not be available to the end user, causing
inconsistent behavior.
3. Use PHP authoring tools to create your PHP solution, incorporating the FileMaker API functions
into your PHP code to access your FileMaker data. See chapter 8, “Using the FileMaker API for
PHP.”
Chapter 7 | Overview of Custom Web Publishing with PHP 65
4. Copy or move your site directory structure and files to the following folder on the web server.
1 For IIS (Windows) through HTTP or HTTPS:
[drive]:\Program Files\FileMaker\FileMaker Server\HTTPServer\Conf
where [drive] is the drive on which the Web Publishing Engine component of your
FileMaker Server deployment resides.
1 For Apache (OS X) through HTTP:
/Library/FileMaker Server/HTTPServer/htdocs
1 For Apache (OS X) through HTTPS:
/Library/FileMaker Server/HTTPServer/htdocs/httpsRoot
5. If a database container field stores a file reference instead of an actual file, the referenced
container object must be stored in the FileMaker Pro Web folder when the record is created or
edited. You must copy or move the object to a folder with the same relative location in the root
folder of the web server software.
See “About publishing the contents of container fields on the web” on page 15.
6. Make sure that security mechanisms for your site or program are in place.
7. Test your site using the same accounts and privileges defined for web users.
8. Make the site available and known to users. The URL that the web user enters follows this format:
http://<server>/<site_path>
1 <server> is the machine on which the FileMaker Server resides
1 <site_path> is the relative path to the home page for your site, determined by the directory
structure you used in step 4 above.
For example, if your web server is 192.168.123.101 and your site home page is on the web server
at c:\Inetpub\wwwroot\customers\index.php, then the web user would enter this URL:
http://192.168.123.101/customers/index.php
Note PHP uses Latin-1 (ISO-8859-1) encoding. FileMaker Server returns Unicode (UTF-8) data.
Use the FileMaker Server Admin Console to specify the default character encoding for your site.
For PHP sites, you can specify either UTF-8 or ISO-8859-1; UTF-8 is recommended. Specify the
same setting for the charset attribute in the <HEAD> section of your site PHP files.
For information on deploying and using a PHP solution, see chapter 9, “Staging, testing, and
monitoring a site.”
Chapter 8
Using the FileMaker API for PHP
The FileMaker API for PHP implements a PHP class—the FileMaker class—that provides an
object-oriented interface to FileMaker databases. The FileMaker API for PHP enables both data
and logic stored in FileMaker Pro databases to be accessed and published on the web, or
exported to other applications.
The FileMaker API for PHP allows PHP code to perform the same kind of functions you already
have available in FileMaker Pro databases:
1 create, delete, edit, and duplicate records
1 perform find requests
1 perform field and record validation
1 use layouts
1 run FileMaker scripts
1 display portals and related records
1 use value lists
This chapter describes how to use the FileMaker class objects and methods to add these common
functions to a PHP solution. This chapter does not cover the entire the FileMaker API for PHP, but
introduces key objects and methods.
Note The hostspec property defaults to the value http://localhost. If the PHP engine is
running on the same machine as the web server component of the FileMaker Server deployment,
there is no need to specify the hostspec property. If the PHP engine is on a different machine, use
the hostspec property to specify the location of the web server component of the FileMaker Server
deployment.
Creating a record
There are two ways to create a record:
1 Use the createRecord() method, specifying a layout name, and optionally specifying an
array of field values. You can also set values individually in the new record object.
The createRecord() method does not save the new record to the database. To save the
record to the database, call the commit() method.
For example:
$rec = $fm->createRecord('Form View', $values);
$result = $rec->commit();
Chapter 8 | Using the FileMaker API for PHP 69
Duplicating a record
Duplicate an existing record using the Duplicate command. Use the newDuplicateCommand()
method to create a FileMaker_Command_Duplicate object, specifying the layout name and the
record ID of the record that you want to duplicate. Then, duplicate the record by calling the
execute() method.
Example
$newDuplicate = $fm->newDuplicateCommand('Respondent', $rec_ID);
$result = $newDuplicate->execute();
Editing a record
There are two ways to edit a record:
1 Using the Edit command. Use the newEditCommand() method to create a
FileMaker_Command_Edit object, specifying the layout name, the record ID of the record you
want to edit, and an array of values that you want to update. Then, edit the record by calling the
execute() method.
For example:
$newEdit = $fm->newEditCommand('Respondent', $rec_ID, $respondent_data);
$result = $newEdit->execute();
1 Using a record object. Retrieve a record from the database, change field values, and then edit
the record by calling the commit() method.
For example:
$rec = $fm->getRecordById('Form View', $rec_ID);
$rec->setField('Name', $nameEntered);
$result = $rec->commit();
Deleting a record
There are two ways to delete a record:
1 Retrieve a record from the database, and then call the delete() method.
For example:
$rec = $fm->getRecordById('Form View', $rec_ID);
$rec->delete();
Chapter 8 | Using the FileMaker API for PHP 70
1 Delete an existing record using the Delete command. Use the newDeleteCommand() method
to create a FileMaker_Command_Delete object, specifying the layout name and the record ID
of the record you want to delete. Then, delete the record by calling the execute() method.
For example:
$newDelete = $fm->newDeleteCommand('Respondent', $rec_ID);
$result = $newDelete->execute();
Example
$scripts = $fm->listScripts();
Example
$newPerformScript = $fm->newPerformScriptCommand('Order Summary',
'ComputeTotal');
$result = $newPerformScript->execute();
Example
$findCommand = $fm->newFindCommand('Students');
$findCommand->addFindCriterion('GPA', $searchValue);
$findCommand->setPreCommandScript('UpdateGPA');
$result = $findCommand->execute();
Chapter 8 | Using the FileMaker API for PHP 71
Example
$findCommand = $fm->newFindCommand('Students');
$findCommand->setPreSortScript('RemoveExpelled');
Example
$findCommand = $fm->newFindCommand('Students');
$findCommand->setScript('myScript','param1|param2|param3');
4. Sort the Find result set, if the addSortRule() method was specified.
If one of the above steps generates an error code, the command execution stops; any steps that
follow are not executed. However, any prior steps in the request are still executed.
For example, consider a command that deletes the current record, sorts the records, and then
executes a script. If the addSortRule() method specifies a non-existent field, the request
deletes the current record and returns error code 102 (“Field is missing”), but does not execute
the script.
Chapter 8 | Using the FileMaker API for PHP 72
Using portals
A portal is table that displays rows of data from one or more related records. The FileMaker class
defines a related set object and several methods that allow you to work with portals defined in a
FileMaker Pro database.
A related set object is an array of record objects from the related portal; each record object
represents one row of data in the portal.
Example
$tableNames = $currentLayout->listRelatedSets();
Example
$relatedSetsNames = $result->getRelatedSets();
Chapter 8 | Using the FileMaker API for PHP 73
Example
$relatedSetsArray = $currentLayout->getRelatedSets();
Example
$relatedSet = $currentLayout->getRelatedSet('customers');
Example
$tableName = $relatedSet->getName();
Example
$relatedRecordsArray = $currentRecord->getRelatedSet('customers');
Example
//create a new portal row in the 'customer' portal
$new_row = $currentRecord->newRelatedRecord('customer');
$result = $new_row->commit();
Chapter 8 | Using the FileMaker API for PHP 74
Example
$relatedSet = $currentRecord->getRelatedSet('customers');
/* Runs through each of the portal rows */
foreach ($relatedSet as $nextRow) {
$nameField = $nextRow->getField('customer::name')
if ($nameField == $badName ) {
$result = $newRow->delete();
}
}
Example
$valueListNames = $currentLayout->listValueLists();
Example
$valueListsArray = $currentLayout->getValueListsTwoFields();
Note Although the getValueLists() method is still supported in the FileMaker API for PHP,
it will be deprecated. Instead, use the getValueListsTwoFields() method.
Depending on the options selected in the Specify Fields for Value List dialog box in the FileMaker
database, the getValueListTwoFields() method returns the value in the first field only, the
value in the second field only, or the values in both fields of a value list as the stored and displayed
values.
1 If Also display values from second field is not selected, the getValueListTwoFields()
method returns the value from the first field of the value list as both the stored value and the
displayed value.
1 If Also display values from second field and Show values only from second field are both
selected, the getValueListTwoFields() method returns the value from the first field as
the stored value, and the value from the second field as the displayed value.
1 If Also display values from second field is selected and Show values only from second
field is not selected, the getValueListTwoFields() method returns the value from the first
field as the stored value, and both values from the first and second fields as the displayed value.
Use an iterator with the getValueListTwoFields() method to find the displayed value and
stored value.
Example
$layout = $fm->getLayout('customers');
$valuearray = $layout->getValueListTwoFields("region", 4);
foreach ($valuearray as $displayValue => $value) {
....
}
Notes
1 Although the getValueList() method is still supported in the FileMaker API for PHP, it will
be deprecated. Instead, use the getValueListTwoFields() method.
1 When using the getValueListTwoFields() method, be sure to use a foreach loop to loop
through the associative array. Do not use a for loop because it can return unexpected results.
The FileMaker class also defines several methods that can be used for all four types of Find
commands:
1 Use the addSortRule() method to add a rule defining how the result set is sorted. Use the
clearSortRules() method to clear all sort rules that have been defined.
1 Use the setLogicalOperator() method to change between logical AND searches and
logical OR searches.
Chapter 8 | Using the FileMaker API for PHP 76
1 Use the setRange() method to request only part of the result set. Use the getRange()
method to retrieve the current range definition.
Using the setRange() method can improve the performance of your solution by reducing the
number records that are returned by the Find request. For example, if a Find request returns
100 records, you can split the result set into five groups of 20 records each rather than
processing all 100 records at once.
1 You can execute FileMaker scripts in conjunction with Find commands.
1 To run a script before executing the Find command, use the setPreCommandScript()
method.
1 To run a script before sorting the result set, use the setPreSortScript() method.
1 To run a script after a result set is generated, but before the result set is sorted, use the
setScript() method.
Example
$findCommand = $fm->newFindAllCommand('Form View');
$result = $findCommand->execute;
Note When using the Find All command, avoid computer memory overload problems by
specifying a default maximum number of records to return per page.
Example
$findCommand = $fm->newFindAnyCommand('Form View');
$result = $findCommand->execute;
1 time of day
Valid data is a character string representing a 12-hour time value in the one of these formats:
1 H
1 H:M
1 H:M:S
1 H:M:S AM/PM
1 H:M AM/PM
where H is a number between 1 and 12 inclusive; M and S are numbers between 1 and 60
inclusive.
The PHP engine pre-validation supports implicit checking of field data based on the type of the field:
1 date
A field defined as a date field is validated according to the rules of “four-digit year” validation,
except the year value can contain 0-4 digits (the year value can be empty). For example, 1/30
is a valid date even though it has no year specified.
1 time
A field defined as a time field is validated according to the rules of “time of day” validation,
except the hour component (H) can be a number between 1 and 24 inclusive to support 24-hour
time values.
1 timestamp
A field defined as a timestamp field is validated according to the rules of “time” validation for the
time component and according to the rules of “date” validation for the date component.
The FileMaker class cannot pre-validate all of the field validation options that are available in
FileMaker Pro. The following validation options cannot be pre-validated because they are
dependent on the state of all the data in the database at the time that the data is committed:
1 unique value
1 existing value
1 in range
1 member of value list
1 validate by calculation
Pre-validating records
For a record object, use the validate() method to validate one field or all the fields in the record
against the pre-validation rules enforceable by the PHP engine. If you pass the optional field name
argument, only that field is pre-validated.
If the pre-validation passes, then the validate() method returns TRUE. If the pre-validation
fails, then the validate() method returns a FileMaker_Error_Validation object containing
details about what failed to validate.
Pre-validating fields
For a field object, use the validate() method to determine whether a given value is valid for a
field.
If the pre-validation passes, then the validate() method returns TRUE. If the pre-validation
fails, then the validate() method returns a FileMaker_Error_Validation object containing
details about what failed to validate.
2. A validation constant value that indicates the validation rule that failed:
1 - FILEMAKER_RULE_NOTEMPTY
2 - FILEMAKER_RULE_NUMERICONLY
3 - FILEMAKER_RULE_MAXCHARACTERS
4 - FILEMAKER_RULE_FOURDIGITYEAR
5 - FILEMAKER_RULE_TIMEOFDAY
6 - FILEMAKER_RULE_TIMESTAMP_FIELD
7 - FILEMAKER_RULE_DATE_FIELD
8 - FILEMAKER_RULE_TIME_FIELD
3. The actual value entered for the field that failed pre-validation
You can also use the following methods with a FileMaker_Error_Validation object:
1 Use the isValidationError() method to test whether the error is a validation error.
1 Use the numErrors() method to get the number of validation rules that failed.
Chapter 8 | Using the FileMaker API for PHP 83
Example
//Create an Add request
$addrequest = $fm->newAddCommand('test', array('join' => 'added', 'maxchars' =>
'abcx', 'field' => 'something' , 'numericonly' => 'abc'));
//If the validate() method returned any errors, print the name of the field, the
error number, and the value that failed.
if(FileMaker::isError($result)){
echo 'Validation failed:'. "\n";
$validationErrors= $result->getErrors();
foreach ($validationErrors as $error) {
$field = $error[0];
echo 'Field Name: ' . $field->getName(). "\n";
echo 'Error Code: ' . $error[1] . "\n";
echo 'Value: ' . $error[2] . "\n";
}
}
Output
Validation failed:
Field Name: numericonly
Error Code: 2
Value: abc
Field Name: maxchars
Error Code: 3
Value: abcx
Chapter 8 | Using the FileMaker API for PHP 84
Handling errors
The FileMaker class defines the FileMaker_Error object to help you handle errors that occur in a
PHP solution.
An error can occur when a command runs. If an error does occur, the command returns a
FileMaker_Error object. It is a good practice to check the error that is returned when a command
runs.
Use the following methods to learn more about the error indicated in the FileMaker_Error object.
1 Test for whether a variable is a FileMaker Error object by calling the isError() method.
1 Get the number of errors that occurred by calling the numErrors() method.
1 Retrieve an array of arrays describing the errors that occurred by calling the getErrors()
method.
1 Display an error message by calling the getMessage() method.
Example
$result = $findCommand->execute();
if (FileMaker::isError($result)) {
echo "<p>Error: " . $result->getMessage() . "</p>";
exit;
}
For information about the error codes returned with the FileMaker Error object, see appendix A,
“Error codes for Custom Web Publishing.”
Chapter 9
Staging, testing, and monitoring a site
This chapter provides instructions for staging and testing a Custom Web Publishing site before
deploying it in a production environment. Instructions are also provided for using log files to
monitor the site during testing or after deployment.
2. Check that Custom Web Publishing has been enabled and properly configured in
FileMaker Server Admin Console.
3. Verify that the web server and the Web Publishing Engine are running.
4. Copy or move your site files to the web server component of your FileMaker Server
deployment.
Copy or move your site files to the following directory on the web server machine:
1 IIS (Windows) through HTTP or HTTPS:
[drive]:\Program Files\FileMaker\FileMaker Server\HTTPServer\Conf
where [drive] is the drive on which the Web Publishing Engine component of your
FileMaker Server deployment resides.
1 Apache (OS X) through HTTP: /Library/FileMaker Server/HTTPServer/htdocs
1 Apache (OS X) through HTTPS: /Library/FileMaker Server/HTTPServer/htdocs/httpsRoot
Chapter 9 | Staging, testing, and monitoring a site 86
5. If you have not already done so, copy or move any referenced container field objects to the
appropriate directory on the web server machine.
1 If the database file is properly hosted and accessible on the Database Server component of
the FileMaker Server deployment, and the container fields store the actual files in the
FileMaker database, then you don’t need to relocate the container field contents.
1 If a database container field stores a file reference instead of an actual file, then the
referenced container object must be stored in the FileMaker Pro Web folder when the record
is created or edited. To stage your site, you must copy or move the referenced containers to
a folder with the same relative location in the root folder of the web server software.
1 When you use FileMaker Pro to upload a database with container fields that store objects
externally, the externally stored container field data is uploaded to FileMaker Server as part of
the process. See FileMaker Pro Help for information on transferring the database files to
FileMaker Server.
1 When you manually upload a database that uses a container field with externally stored
objects, then you must copy or move the referenced objects into a subfolder of the
RC_Data_FMS folder, as described in “Container fields with externally stored data” on
page 16.
6. Copy any additional components of your web application to the web server machine. For
Custom Web Publishing with XML, your web application processes the XML data before
sending it to another application or to the client.
Note If you have installed the web server, Web Publishing Engine, and the Database Server in
a single-machine deployment, you can view and test your site without using a network connection
by using http://127.0.0.1/ in the URL.
1 When debugging a stylesheet, you can use the following example of an HTML <textarea> tag
to display the XML source document that was accessed via the stylesheet in a scrolling text
area.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fmrs="http://www.filemaker.com/xml/fmresultset">
<xsl:output method="html"/>
<html>
<body>
<xsl:template match="/fmrs:fmresultset">
<textarea rows="20" cols="100">
<xsl:copy-of select="."/>
</textarea><br/>
</xsl:template>
</body>
</html>
</xsl:stylesheet>
Note For information on the W3C Common Logfile Format and the W3C Extended Log File
Format, see the World Wide Web Consortium website at http://www.w3.org.
The Error level messages setting is enabled by default. For information on setting these options
using Admin Console, see FileMaker Server Help.
Important Over time, the wpe.log file may become very large. Use Admin Console to set the
maximum size for the wpe.log file. When the wpe.log file reaches this maximum size, the Web
Publishing Engine copies the wpe.log file to a single backup file, wpe.log.1, and creates a new
wpe.log file. You may wish to save an archive of the wpe.log.1 file on a regular basis, if you want
more than one backup copy.
Chapter 9 | Staging, testing, and monitoring a site 89
1 System errors
2015-06-02 15:30:42 -0700 WPC_SERVER 192.168.100.101:0 jdoe XML
ERROR - - Communication failed
B D
Basic Authentication for web users 13 database error codes 29, 91
database layouts available 48
C database object 68
Change Password script 14 databases, protecting when published 14
clearSortRules() method 75 <datasource> element 30
client URL library 61 date field 81
commands for queries. See query strings date representation 79
commit() method 68 –db query parameter 49
comparison of XML grammars 28 –dbnames query command 46
comparison operators for fields 51 Delete command 70
Compound Find –delete query command 46
command 77 –delete.related query parameter 45
example 78 delete() method 69, 74
compound find deleting a record 69
query command 48 deleting portal records 45
query parameter 53 document type definitions (DTDs) 29, 33
connecting to a FileMaker database using PHP 68 documentation 8
container fields –dup query command 47
how web users access data 18 Duplicate command 69
progressive download 17 duplicating a record 69
publishing contents of 15
dynamic IP address 61
URL syntax for accessing in XML solutions 27
with externally stored data 16
with referenced files 15 E
createRecord() method 68 Edit command 69
creating a record –edit query command 47
using PHP 68 editing a record 69
using XML 48 elements
cURL 61 database error code 29
in FMPXMLLAYOUT grammar 35
in FMPXMLRESULT grammar 33
in fmresultset grammar 30
enabling Custom Web Publishing in a database 13
93
N
name attribute 31
namespaces for XML 29
95
X
XML
advantages 11
Custom Web Publishing, described 11
described 24
document type definitions (DTDs) 29, 30, 33
enabling in a database 13
encoded using UTF-8 format 29, 38
FMPXMLLAYOUT grammar 35
FMPXMLRESULT grammar 33
fmresultset grammar 30
<datasource> element 30
<field-definition> element 31
<metadata> element 31
<relatedset-definition> element 31
<resultset> element 31
generating XML data from request 25
grammars compared 28
namespaces for 29
order of request processing 40
parsers 26, 38
query strings 38, 42
request, specifying layout 40
requesting data 26
response, switching layout 40
summary of steps for accessing XML data 26
troubleshooting access to XML documents 41
URL text encoding 28
XML 1.0 specification 24
<xsl:stylesheet> element 87
<xsl:template> element 87