February 21, 20187 yr I really am not sure where to start with this. I would like some fields of a database (hosted on FMS) to show on a webpage and be searchable. I can do this through web direct but I would prefer a user not to be kicked out of the company website to go to a web direct one. Any thoughts and guidance? Unfortunately im not good a web coding nor understanding the protocols for interaction. thanks
February 21, 20187 yr This is what Custom Web Publishing (CWP) is for using the PHP API. In short, web pages in your main company website can be outfitted with php code to offer the search form you desire, the ability to query your FMP database and return data in the format you desire. Every FMS system since version 7 offers this capability. It provides a “normal” web experience for your end user. That’s the good news. The hurdle of using CWP is mastering the full stack of tools that are involved: HTML, CSS, PHP, the PHP API, Apache/IIS, and probably JavaScript, JQuery, AJAX , BootStrap... and more... too much to ask when you just want to get it done I’ve dedicated myself to CWP since it was introduced by FileMaker. If you contact me directly, I can provide some time and cost estimate. Or, take a look at my website for some examples. www.exit445.com Good Luck! Jonathan
February 21, 20187 yr I started here https://bluefeathergroup.com/blog/introduction-to-filemaker-custom-web-publishing-cwp/ I didn't know any CWP a couple of months ago - now I'm comfortable with reading PHP/JavaScript and can adapt code snippets from around the web. Good luck.
February 21, 20187 yr Author Thanks I’ll get reading. this looked useful too http://sixfriedrice.com/wp/up-to-speed-with-the-filemaker-php-api/ Edited February 21, 20187 yr by Aussie John
February 22, 20187 yr Author I have followed the link IdeaData suggested but I am getting this error on trying to log onto the page Communication Error: (22) The requested URL returned error: 503 Service Unavailable - This can be due to an invalid username or password, or if the FMPHP privilege is not enabled for that user. As far as I can see I have password set up correctly and FMPHP is selected. As a bit of a check - web direct is working but it gives a message that my certificate is only the default one and that some items might be missing. Is this a possible culprit?
February 23, 20187 yr Error 22 in CWP is the catchall for a failed connection between the API and FMS. Although the message mentions username and password as potential causes, the list is much broader than that. For perspective, I wrestle with Error 22 on nearly every new project until all the settings are tweaked. One setting that I don’t believe I saw mentioned...have you opened the required ports on the server firewall?
February 24, 20187 yr Author The firewall is open for 80,81,443 and 444 anything else? As FMS server uses 81/444 I should try adding :81 to the domain?
February 24, 20187 yr There are slew of them, depending on whether you have a one machine or two machine installation, and what version of FMS we're talking about. See this page to pick your FMS version. https://support.filemaker.com/s/answerview?language=en_US&anum=14402 Hope that helps.
February 26, 20187 yr Author Thanks appreciate the help OK some progress: I checked the ports and they were OK so I changed the code to that suggested in http://sixfriedrice.com/wp/up-to-speed-with-the-filemaker-php-api/ (FYI the the blue feather tutorial code didn't authenticate). https://arina.biz/testprojects.php directs to what appears to be an authenticated page for my domain, except it is blank. Here is the code. <?php include("filemaker.php"); $connection =& new FileMaker("TestProjects", "fms.arina.biz"); $connection->setProperty(‘username’, ‘PHP User’); $connection->setProperty(‘password’, ‘arina’); $cmd =& $connection->newFindCommand(‘PHP test’); $cmd->addFindCriterion(‘Name’, ‘pamela’); $result = $cmd->execute(); if (FileMaker::isError($result)) { echo ‘unable to find Pamela: ‘ . $result->message . ‘(‘ . $result->code . ‘)’; die(); } ?> For info I have attached a local version of the hosted file. thanks for any assistance. TestProjects.fmp12
February 26, 20187 yr Aussie John: Based on your code, it SHOULD be blank. You are only echoing a result if there is an error. What do want to do with the found record?
February 26, 20187 yr Author For this exercise, display the result "Pamela" - based on $cmd->addFindCriterion(‘Name’, ‘pamela’). But what I am working toward is for the user to perform a quick find I added hoping this might work (sadly not). <?php include("filemaker.php"); $connection =& new FileMaker("TestProjects", "fms.arina.biz"); $connection->setProperty(‘username’, ‘PHP User’); $connection->setProperty(‘password’, ‘arina’); $cmd =& $connection->newFindCommand(‘PHP test’); $cmd->addFindCriterion(‘Name’, ‘pamela’); $result = $cmd->execute(); if (FileMaker::isError($result)) { echo ‘unable to find Pamela: ‘ . $result->message . ‘(‘ . $result->code . ‘)’; die(); } $record = $result->getAllrecords(); $name = $record->getField("Name"); $color = $record->getField("Favorite Color"); echo("$name - $color"); ?> cheers
February 26, 20187 yr Try this: $records = $result->getRecords(); $record = $records[0]; $name = $record->getField("Name"); $color = $record->getField("Favorite Color"); echo $name.’ - ‘. $color;
February 26, 20187 yr Author JB Sorry to report but this still leaves a blank page. <?php include("filemaker.php"); $connection =& new FileMaker("TestProjects", "fms.arina.biz"); $connection->setProperty(‘username’, ‘PHP User’); $connection->setProperty(‘password’, ‘arina’); $cmd =& $connection->newFindCommand(‘PHP test’); $cmd->addFindCriterion(‘Name’, ‘pamela’); $result = $cmd->execute(); if (FileMaker::isError($result)) { echo ‘unable to find Pamela: ‘ . $result->message . ‘(‘ . $result->code . ‘)’; die(); } $records = $result->getRecords(); $record = $records[0]; $name = $record->getField("name"); $color = $record->getField("favorite color"); echo $name.’ - ‘. $color; ?> EDIT; Changed Echo to Echo 'xxx' and nothing returns either Edited February 26, 20187 yr by Aussie John additional info
February 26, 20187 yr Aussie John, Not sure if the single quotes you are using are "legal." I just tried the code on my local machine and got a syntax error... another source of seeing a black page. To be sure, change all to double quotes. When I did that, the page did run but returned a different error but I'm not running the current PHP API on my local development machine. What do you get? I
February 26, 20187 yr Author Chrome gives me an HTTP 500 error which from my search can be; " A Permissions Error. In most cases, a 500 Internal Server Error is due to an incorrect permission on one or more files or folders. In most of those cases, an incorrect permission on a PHP and CGI script is to blame. These should usually be set at 0755 (-rwxr-xr-x). EDIT the permissions although not what the web search indicated are the same as other accessible files. (see below) drwxr-xr-x+ 25 svradmin admin 850 26 Feb 17:12 . drwxrwxr-x+ 10 root admin 340 26 Feb 14:53 .. -rw-r--r--@ 1 svradmin admin 6148 26 Feb 16:58 .DS_Store drwxr-xr-x+ 14 svradmin admin 476 26 Feb 17:09 FileMaker -rw-r--r--+ 1 svradmin admin 14751 5 Apr 2017 FileMaker.php -rw-r--r--@ 1 svradmin admin 626 26 Feb 16:38 TestProjects.php drwxr-xr-x+ 2 svradmin admin 68 26 Feb 14:51 blocs-export-img -rw-r--r--@ 1 svradmin admin 12452 26 Feb 14:52 briefing-and-projects.html -rw-r--r--@ 1 svradmin admin 11737 15 Feb 10:15 briefing.html -rw-r--r--@ 1 svradmin admin 5119 26 Feb 14:52 contact-us.html drwxr-xr-x+ 5 john admin 170 21 Feb 17:10 css -rw-r--r--@ 1 svradmin admin 41562 15 Jul 2016 favicon.png drwxr-xr-x+ 8 svradmin admin 272 14 Feb 12:40 fonts drwxr-xr-x+ 46 john admin 1564 21 Feb 17:13 img -rwxrwxrwx@ 1 svradmin admin 7592 26 Feb 14:52 index.html drwxr-xr-x+ 7 john admin 238 21 Feb 17:10 js -rw-r--r--@ 1 svradmin admin 11564 26 Feb 14:52 masterplans-and-project-definition.html -rw-r--r--@ 1 svradmin admin 10862 15 Feb 10:15 masterplans.html -rw-r--r--@ 1 svradmin admin 1135 26 Feb 14:52 sitemap.xml -rw-r--r--@ 1 svradmin admin 7385 26 Feb 14:52 staff.html -rwxrwxrwx@ 1 svradmin admin 23835 26 Feb 14:52 style.css -rw-r--r--@ 1 svradmin admin 33 26 Feb 16:01 test.php -rw-r--r--@ 1 svradmin admin 9193 26 Feb 14:52 testimonials.html -rw-r--r--@ 1 svradmin admin 2728 26 Feb 12:02 testing.html -rw-r--r--@ 1 svradmin admin 3371 26 Feb 14:52 testing.php I also changed the quotes to no effect Edited February 26, 20187 yr by Aussie John
February 26, 20187 yr 19 hours ago, Aussie John said: $connection =& new FileMaker("TestProjects", "fms.arina.biz"); $connection->setProperty(‘username’, ‘PHP User’); $connection->setProperty(‘password’, ‘arina’); You can try to remove the "&" after the equals sign in the first line here. Also, you can try adding "https://" in front of the host. You can also add this line in your PHP to toggle showing errors in the php code: ini_set('display_errors',1); And to turn it off, set to: ini_set('display_errors',0); The WPE only uses 80 or 443, depending if you have SSL turned on or not. If you do not have SSL enabled, then you would use http:// on the default port, 80. Mike
February 26, 20187 yr Author Mike I amended the script as suggested but sadly to no avail. Safari still shows a blank page and chrome shows "HTTP error 500"
February 26, 20187 yr Please visit the FMS Custom Web Publishing Test page to confirm that the server is working properly.
February 26, 20187 yr Author Good morning JB CWP is working according to the test page. I have run this script for testprojects.php to test the connection. <?php include("filemaker.php"); ini_set("display_errors",1); //And to turn it off, set to: //ini_set("display_errors",0); $connection =new FileMaker("TestProjects", "https://fms.arina.biz:444"); $connection->setProperty("username", "PHP User"); $connection->setProperty("password", "arina"); $connected = $connection->listLayouts(); If(FileMaker::isError($connected)){ echo "not connected"; } else { echo 'connected'; } ?> which returns NOT connected if I make an intentional error of $connected = $connectionS->listLayouts(); I get the following message Notice: Undefined variable: connections in /Library/Server/Web/Data/Sites/ARINA 2018/testprojects.php on line 14 Fatal error: Call to a member function listLayouts() on null in /Library/Server/Web/Data/Sites/ARINA 2018/testprojects.php on line 14 That tells me that PHP is being read but the final connection to FM isn't working. So to go back to basics: I have my root web folder ARINA 2018 which includes the Filemaker folder and the Filemaker.php and the testprojects.php - this is the correct location? Edited February 26, 20187 yr by Aussie John
February 27, 20187 yr That path does not look right to me. Please read the CWP manual at https://fmhelp.filemaker.com/docs/15/en/fms15_cwp_guide.pdf. In particular section 7 paragraph 4 Quote 4. Copy or move your site directory structure and files to the following folder on the web server. 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. For Apache (OS X) through HTTP: /Library/FileMaker Server/HTTPServer/htdocs For Apache (OS X) through HTTPS: /Library/FileMaker Server/HTTPServer/htdocs/httpsRoot Incidentally, your test layout name is actually "PHP Test", not "PHP test" as you have used earlier.
February 27, 20187 yr 14 hours ago, Aussie John said: $connection =new FileMaker("TestProjects", "https://fms.arina.biz:444"); You might try setting the properties more explicitly, just to make sure they are in the right order. Your test page appears to be working correctly on the port you specify, but it could also be an authentication error with the credentials you use. Also make sure to have both XML and PHP privilege sets enabled for the "PHP User" account, if that is the one you are using. Both are needed. $fm = new FileMaker(); $fm->setProperty('database', 'TestProjects'); $fm->setProperty('hostspec', 'https://fms.arina.biz:444/'); $fm->setProperty('username', 'PHP User'); $fm->setProperty('password', 'arina');
February 27, 20187 yr I was able to make your php script work with the following changes: The file was riddled with curly single quotes. I changed the login to one I was most familiar with (without the setProperty() syntax) Made the find request layout name match the layout name in the FM file. Changed the include command to show the correct pathname and filename for FileMaker.php (on my system; YMMV) Changed some capitalization. PHP is case-sensitive. I added the sequence using $accessed. I find it a very useful troubleshooting tool, as well as a visual cue for a user when the server is down. HTH EDIT: Even though the attached file is pointed to the copy of your database on my server, I also connected successfully to your server fms.arina.biz aussiejohnTest.php Edited February 27, 20187 yr by doughemi
March 1, 20187 yr Author On 27/02/2018 at 8:01 PM, IdealData said: That path does not look right to me. Please read the CWP manual at https://fmhelp.filemaker.com/docs/15/en/fms15_cwp_guide.pdf. In particular section 7 paragraph 4 Incidentally, your test layout name is actually "PHP Test", not "PHP test" as you have used earlier. Hi Idealdata - are you saying I should move my website date to this folder - Filemaker and web server are on different machines
March 6, 20187 yr AussieJohn - it would be a good test to follow the FMI instructions. Might help to resolve your issues. Get it working there first.
April 3, 20187 yr Author Thanks Doughemi - I can indeed connect to the FM Server with a "connected" message but it still doesn't show any Filemaker results. And thanks IdeaData too. I have read the instruction (chapter 7 para 4) but I don't understand it . Im assuming site directory structure refers to my Web data? so why would I move this - no one would find it - as web and file-maker are on different machines. Also the Web Server doesn't have that folder. Clearly I am not understanding what is expected here. Manual quote Copy or move your site directory structure and files to the following folder on the web server. For Apache (OS X) through HTTPS: /Library/FileMaker Server/HTTPServer/htdocs/httpsRoot Edited April 3, 20187 yr by Aussie John
April 3, 20187 yr Aussie John. I suggested you follow the FMI instructions to test matters - that would at least give you some clues. Thanks.
April 3, 20187 yr PHP files need to be in that directory if FMS and web server are on the same box. In your case, that does not apply. Can you post your PHP connect to FM file so we can see if there are any errors there?
April 3, 20187 yr Aussie John. I loaded your test file on my own server and used the code by doughemi. The code has a fault in the error trap - there is no method for code(), it is actually getCode(), see below my modification: <?php //================================= define('FM_HOST', "localhost"); $fm_file = "TestProjects"; $fm_user = 'PHP User' ; $fm_pass = 'arina'; include("FileMaker.php"); //include ('include/filemaker14/FileMaker.php'); # instantiate a new FileMaker object $connection = new FileMaker($fm_file, FM_HOST, $fm_user, $fm_pass); $accessed = $connection->listLayouts(); if(FileMaker::isError($accessed)){ echo $accessed->getMessage(); echo "Sorry, the database is not available at this time.<br /><br />Please use your browser's back button to return to the AMYA webpage."; exit; } else{// else not usually left in file; it is here for testing purposes print_r($accessed); echo '<br>'; } $cmd =& $connection->newFindCommand('PHP Test'); $cmd->addFindCriterion('Name', 'xpamela'); $result = $cmd->execute(); if (FileMaker::isError($result)) { echo 'unable to find Pamela: ' . $result->getMessage() . '(' . $result->getCode() . ')'; die(); } $records = $result->getRecords(); $record = $records[0]; $name = $record->getField("Name"); $color = $record->getField("favorite color"); echo $name.' - '. $color; ?> Now the error trap actually works and should return you a FileMaker error code - notice I have changed the find criterion to 'xpamela' to deliberately force the error - which is of course a 401. getCode() is NOT DOCUMENTED in the Filemaker API for PHP Documents, nor in the Custom Web Publishing Guide and IS INCORRECT on the sixfriedrice blog (I think that's where you started from?). See also the following posting to confirm the undocumented "feature" (!!) https://fmforums.com/topic/74737-geterror-as-code-not-text/ 10-4.
April 4, 20187 yr Author Thanks Idealdata - that is very helpful. I am now getting results from the database.
April 5, 20187 yr Author Firstly Thanks to everyone who help get me started. Not surprisingly I have plenty of questions but I think I will start a new thread.
April 5, 20187 yr Author If anyone is interested here is the final code - (which can be viewed at Arina.biz/testprojects.php ) <?php //================================= define('FM_HOST', "localhost"); $fm_file = "TestProjects"; $fm_user = 'PHP User' ; $fm_pass = 'arina'; $layout_name = 'People'; include("FileMaker.php"); //include ('include/filemaker14/FileMaker.php'); # instantiate a new FileMaker object $connection = new FileMaker($fm_file, 'https://fms.arina.biz:444', $fm_user, $fm_pass); $accessed = $connection->listLayouts(); if(FileMaker::isError($accessed)){ echo $accessed->getMessage(); echo "Sorry, the database is not available at this time.<br /><br />Please use your browser's back button to return to the ARINA webpage."; exit; } // else{ // // else not usually left in File; it is here for testing purposes // // print_r($accessed); // echo '<br><br>'; // } Echo 'Enter a colour and click <b>SUBMIT</b> (or <b>RETURN</b> key)<br>Separate multiple colours with a space<br><br>'; ?> <form action='testprojects.php' method="post" enctype="multipart/form-data"> <input type="text" name="search"> <input type="submit"> </form> <?php $find = $_POST['search']; $cmd =& $connection->newFindCommand('People'); $cmd->addFindCriterion('colour', $find); $result = $cmd->execute(); if (FileMaker::isError($result)) { echo 'Unable to find this colour: ' . $result->getMessage() . ' - ERROR CODE (' . $result->getCode(). ')'; die(); } $records = $result->getRecords(); $record = $records[0]; //the GET VALUE COMMAND $options = $record->getField("Getvalue"); echo 'Choose from… '.$options.'<br><br>'; echo 'Last searched for… '.$find,'<br>'; echo '<br> Found…<br>'; foreach ($records as $record) { $name = $record->getField("FirstName"); $color = $record->getField('colour'); echo $name.' - '. $color; echo '<br>'; } ?> ) Edited April 6, 20187 yr by Aussie John
April 5, 20187 yr Author One thing that is eluding me (well actually multiple things) but when the page first loads it is supposed to show a list of colours that are in the database (from a calculation field of the valuelistitems). Unfortunately this only shows after the first search is run. If I move the list before the find commands the find stops working or the input box doesn't show.
April 6, 20187 yr You have to access the database twice: once to download the list of available colors (before displaying it in html or a php echo statement) and again after the form is submitted (so that $_POST['search'] is populated. Check your PM.
Create an account or sign in to comment