October 23, 200916 yr I'm trying to allow users to create comments for individuals. One individual may have many comments (which are timestamped). I have a web page with two buttons (see attached). One allows the user to update notes. This is a text field in the individuals table and is working fine. The other button is meant to create a new comment record. I've not been able to get this to work. I'm using Lance Halberg's excellent video tutorial by VTC; however, it seems that he does not cover adding related records in the tutorial. I found this site to be helpful - http://blog.expertzweb.com/programming/filemaker-api-tutorial-for-php - however, the author refers to a custom function which does not appear to be available. The buttons go to another page and here is the code for that page: <?php include("includes/header.html"); include("FileMaker.php"); include("includes/functions.php"); $fm = db_connect(); $recID = $_POST["recID"]; $notes = $_POST["notes"]; if(isset($_POST["update"])){ $notes = htmlspecialchars($notes); $edit = $fm->newEditCommand("web_individuals", $recID); $edit->setField("notes", $notes); $result = $edit->execute(); } elseif(isset($_POST["add_comm"])) { $edit = $fm->newEditCommand("web_individuals", $recID); $rel_rec = $edit->newRelatedRecord("zz_Comm_Logs"); $rel_rec->setField("zz_Comm_Logs::content", "Lorem Ipsum"); $result = $rel_rec->commit(); } error_check($result); header("Location:form_view.php?recID=".$recID); exit; ?> I've tested the if/elseif statements with var_dump(), so I know those are working properly. However, I am not able to add a related record. (Note, for testing purposes, I am hard coding the input data. Once working, I will replace with input tags). In the FMP db itself I have a web layout (web_individuals) with a portal (zz_Comm_Logs). In the Rel. Graph I have made the portal accept new records. Any ideas? Thanks.
October 26, 200916 yr Hi Daniel Does your web account have access privileges to create records in the related table? Another thing you could do is create the new related record directly -- on a layout based on that table -- instead of as a newRelatedRecord: } elseif(isset($_POST["add_comm"])) { $newComm =& $fm->newAddCommand('CommLayout'); $newComm->setField('kf_ParentID', $recID); $newComm->setField('content', 'Lorem Ipsum'); $result = $newComm->execute(); } /* Note: If your current $recID is not the primary key field in the parent record, then you'll need to capture that and use that here instead*/ HTH, -Joel ~~~~~~~~~~~~~~~~~~~~~~~ Joel Shapiro FileMaker Pro database & web design http://www.jsfmp.com 415-269-5055 ~~~~~~~~~~~~~~~~~~~~~~~
October 26, 200916 yr By the way, that tutorial you found online should also be inside your FileMaker Server directory: FileMaker Server/Examples/PHP/Tutorial/English/ -Joel ~~~~~~~~~~~~~~~~~~~~~~~ Joel Shapiro FileMaker Pro database & web design http://www.jsfmp.com 415-269-5055 ~~~~~~~~~~~~~~~~~~~~~~~
October 27, 200916 yr Author Thanks, Joel. You ask a great question regarding permissions. I do have it set up with full-permissions during development. I ended up going with a script to add the related record. The php looks like this: } elseif(isset($_POST["add_comm"])) { $script = $fm->newPerformScriptCommand("zz_Comm_Logs", "add_webCommLog", $recID); $script->execute(); } error_check($result); header("Location:form_view.php?recID=".$recID); exit; The script is attached. Again, I would add input markup for the user to enter content. I haven't done this part yet, but I presume that I can pass that as the third parameter with the record ID with a regEx "/n" and then add a new variable in the script that grabs the second value (maybe using the RightValues() function). Although this method works well, I am still curious what I am doing wrong with the newRelatedRecord method. script.pdf
October 27, 200916 yr Author Joel, thanks for the path to the examples. I didn't know I had them on my machine!
Create an account or sign in to comment