13 Replies Latest reply on Mar 30, 2012 6:04 AM by Gingernut

    Help with PHP FMstudio - adding a script to button

    Gingernut

      I have a little knowledge of html (via Dreamweaver) and next to none of php so am using FMSTudio to create pages.
      Done list, find and detail all ok so getting the hang of it

      I now want to add a button on the detail page that will perform a script of setting fields to the current time and date - I do not even know if this will work (although step not greyed out)

       

      I cannot work out how to do this and not had any luck on the FMstudio forum either.

      Can anybody help me with this.

      Cheers

       

      Cathy

        • 1. Re: Help with PHP FMstudio - adding a script to button
          steve.winter

          Hi Cathy

           

          That is one of the 'issues' with using something like FMStudio to create your pages, they end up being black-boxes…

           

          So the button which you want to add will go on the detail page as viewed by the user in a web browser…? and you want it to run a script in FileMaker…? which will set values for fields which the user is viewing…? is that correct…?? or do you want the button to set the fields in the form on the web browser, and then have the user save that data back into FM…??

           

          Fon't forget that the web is stateless, and that any button on a web page can not 'magically' run a script in FileMaker… you're going to have to set up some form of communication back from the web page to FileMaker to tell FileMaker which script to run, and which records to act upon, assuming that's what you're trying to do…??

           

          Is there somewhere we can see the pages which you've already got working…?? it might help understand what you're trying to do and therefore allow better advice to be given…

           

          Cheers

          Steve

           

           

          created by Gingernut in Using Web Technologies - View the full discussion

          I have a little knowledge of html (via Dreamweaver) and next to none of php so am using FMSTudio to create pages.

          Done list, find and detail all ok so getting the hang of it

           

          I now want to add a button on the detail page that will perform a script of setting fields to the current time and date  - I do not even know if this will work (although step not greyed out)

           

           

          I cannot work out how to do this and not had any luck on the FMstudio forum either.

           

          Can anybody help me with this.

           

          Cheers

           

           

          Cathy

           

          Reply to this message by replying to this email -or- go to the message on FileMaker Technical Network

          Start a new discussion in Using Web Technologies by email or at FileMaker Technical Network

          Manage your email preferences.

           

          FileMaker Developer Conference 2012 • Miami, Florida • July 16-18 • www.filemaker.com/devcon

           

          Steve Winter

          Matatiro Solutions Limited

          steve@matatirosolutions.co.uk

          p:  +44 23 8064 4181

          m: +44 77 7852 4776

          USA: +1 415 315 9912

          2a St. Mary's Road

          Bishopstoke SO50 6BP

           

          Registered in England and Wales: 6300320

          Registered Office: 44 Southchurch Road, Southend, SS1 2LZ

          VAT Registration Number: 916 8809 86

          IMPORTANT: This message is private and confidential. If you have received this message in error, please notify us and remove it from your system.

          • 2. Re: Help with PHP FMstudio - adding a script to button
            Gingernut

            Hi Steve

             

             

            So the button which you want to add will go on the detail page as viewed by the user in a web browser…? YEs

            and you want it to run a script in FileMaker…? which will set values for fields which the user is viewing…? is that correct…??
            or do you want the button to set the fields in the form on the web browser, and then have the user save that data back into FM…??  this one I beleive

             

            In the detail web page there will only be one record (which is an engineer's jobsheet) In FMGO engineer clicks a button which sets the Call accepted time in Filemaker to Get Current Time. 

             

            You can see the IWP version that I am trying to get close to (which looks rubbish at the moment hence trying the Custom Web Publishing)

            All in development so feel free to play

             

            94.169.225.248/fmi/iwp/ and its the FMGO jobsheet file. Useraname ak and password ak.  The first screen shows this engineer's calls outstandoing he tehn selects one to see the detail and clicks the Accept button and same thing with the arrival time. This sets filemaker fields. Would LOVE the same thing in Custom pages which are nowhere near ready but is viewable at 94.169.225.248/jobsheets/detail.php ENter AK in place of Engineer and you will see what I mean. The pahge I want button on is called Jobsheet_1.php (minimal data so far)

             

            I am in VERY early stages and detail sb Home page I know all that but want to see what it possible before tidying it all up.

             

            I do accept what you say about FMstudio but I was getting nowhere on my own and it has got me started also bought Jonathan Stark book only to find it does not really go into scripts.

             

            Fon't forget that the web is stateless, and that any button on a web page can not 'magically' run a script in FileMaker… you're going to have to set up some form of communication back from the web page to FileMaker to tell FileMaker which script to run, and which records to act upon, assuming that's what you're trying to do…??

             

            This is the bit I am struggling with as far as FMstudio goes I can see the scripts but have no idea what to do with them.

             

            If you can point me to any resource that gives step by step on incorporating a script I would be soo grateful I have googled my heart out to no avail.

             

            Thank you

            • 3. Re: Help with PHP FMstudio - adding a script to button
              Gingernut

              PS JUst looking at Six Fried Rice I get the logic of the scripting but how do I get it to only happen on the click of a button?

              • 4. Re: Help with PHP FMstudio - adding a script to button
                Gingernut

                PPS I can get the field to update when I enter the detail record but I want it to only be when something is clicked that this is to happen

                • 5. Re: Help with PHP FMstudio - adding a script to button
                  steve.winter

                  Hi Cathy

                   

                  Ok, so you're going to need your buttons on the web page to call first of all, a PHP script on your server, and at that point, you don't really need to use an FM script, because you can use PHP to set the field instead.

                   

                  On your details page,

                  are you using sessions already…? e.g. is there a session_start(); at the top of the page…? is so, great, if not, then add (exactly) that PHP command. What this will do is allow you to 'capture' data on the (web) server about what record you just delivered to the browser…

                   

                  Somewhere in the php section of Jobsheet_1.php, after you have loaded the record from FileMaker, put this;

                  $_SESSION['currentRecordID'] = $record->getRecordId();

                  $_SESSION['currentJobNo'] = $record->getField(*jobNumberField*);

                   

                  where $record is the name of the variable which holds the FMP result object...

                   

                  Also on that page create a link (or button as you prefer) which will link to a new php file on your server, call that file (say) jobStatus.php… for each of the buttons make the URL like jobStatus.php?action=accept, so as a button it might be;

                  <input type="button" name="accept" />

                  And one for arrived

                  <input type="button" name="accept" />

                   

                  Create your new jobStatus.php file

                   

                  <?php

                        // begin by saying that nothing will be saved

                        $save = false;

                   

                        // see if the action was accept

                        if($_GET['action'] == 'accept') {

                             // it was, so build a PHP array which will hold the update you need to make in FMP

                             // set the name of the field, then the data which you want to go in there. I've assumed that it's

                            // a timestamp field. so date('m/d/Y H:i:s') will put a regular FMP-format timestamp value in

                             // that field. NOTE even if you are in a part of the world that puts dates in the right order (i.e. day

                             // month year, you need to send the data to FMP the wrong way round, i.e. month first

                             $data = array(*acceptFieldName*, date('m/d/Y H:i:s'));

                   

                             // we want to save data, so set save = true

                             $save = true;

                        } elseif($_GET['action'] == 'arrived') {

                             // if it wasn't accept, was it arrived…? if so, set a different field to the same value

                             $data = array(*arrivedFieldName*, date('m/d/Y H:i:s'));

                             $save = true;

                        }

                   

                        // if we have data to save, then perform the call to FileMaker

                       if($save) {

                             // create a connection - replace all the parameters in there with the correct values, in ''

                             $fmp = new FileMaker(*database*, *server*, *username*, *password*);

                   

                             // what do we want to do with that connection, we want to edit data, so create a new edit command

                             // set the layout that the field we want to edit is on, the record ID of the record to change, and the data

                             // that we are sending

                             $cmd = $fm->newEditCommand(*layoutName*, $_SESSION['currentRecordID'], $data);

                   

                             // execute the command

                             $res = $cmd->execute();

                   

                             // at this point you should check to see if there was an error

                             if(FileMaker::isError($res)) {

                                  // and error occurred… put that in a session variable

                                  $_SESSION['lastError'] = '<**p**>An error occurred setting the time<**/p**>';

                             }
                        }

                   

                        // send the user back to the page that they were on...
                        header('Location: /jobsheets/Jobsheet_1.php?JSNumber='.$_SESSION['currentJobNo']);

                   

                  ?>

                   

                  In order to display the error, if it occurs, then you'll also need to make another change to Jobsheet_1.php. Just before all the other fields which you output, add this;

                   

                  if(isset($_SESSION['lastError'])) {

                        echo $_SESSION['lastError'];

                        unset($_SESSION['lastError'];

                  }

                   

                  Hope some of this makes sense, and helps get you a bit further along…

                   

                  Cheers

                  Steve

                  • 6. Re: Help with PHP FMstudio - adding a script to button
                    steve.winter

                    Arrggghhh... some of my code got eaten... there's a really nasty XSS bug in this form isn't it... I can post links in an email and it will get converted into a link by the board...

                     

                    The bit that ended up as

                         <input type="button" name="accept" />

                     

                    Needs to be

                         <**a** href="/jobsheets/jobStatus.php?action=accept"><input type="button" name="accept" /></**a**>

                     

                    And for the arrived one

                         <**a** href="/jobsheets/jobStatus.php?action=arrived"><input type="button" name="accept" /></**a**>

                     

                    Without the ** round the a in each case (only there to stop the board from eating them)

                    • 7. Re: Help with PHP FMstudio - adding a script to button
                      Gingernut

                      Thanks Steve

                       

                      That looks like exactly what I need and in easy chunks - is also going too help me learn the php properly rather than from the black box

                       

                      I am (nearly) always overwhelmed by the help people are prepared to give on this forum, if only the rest of the world were as helpful to one another in times of need

                       

                      I will let you know how I get on later today -

                       

                      Cathy

                      • 8. Re: Help with PHP FMstudio - adding a script to button
                        domhogan@mac.com

                        Hi I found this was easy using FMStudio but needs a bit of experimenting. 

                         

                        1 Using DreamWeaver top menu and click: Insert> Form > Select List/Menu>

                        2 In the pop up box name it the FileMaker "Field name" you want the pop up to be and then click OK

                        3 Highlight the <select name="Example_Field"></select> in Dreamweaver

                        4 Click on the SERVER BEHAVIOR tab and "+" and choose "Value Lists" then "Value List Menu"

                        5 Choose the "Connection, Fm web layout, and Value List and all the code you need appears:

                         

                        Your HTML pop up should look like this in code:

                         

                        <select name="Example_Field" id="Example_Field">

                            <?php

                        foreach(fmsValueListItems($YOURLOGINCONNECTIONAME,'FILEMAKER_WEB_LAYOUT_NAME','YOUR_VALUE_LIST_NAME',"") as $list_item) {

                          if($list_item == $YOUR_FMSTUDIO_CONNECTION_NAME_row->getField('Example_Field')) {

                            echo "<option value=\"{$list_item}\" selected=\"selected\">{$list_item}</option>\n";

                          } else {

                            echo "<option value=\"{$list_item}\">{$list_item}</option>\n";

                          }

                        }

                        ?>

                          </select>

                         

                        Hope that helps. If in trouble go here and watch them I thought they were good: http://www.fmwebschool.com/fmstudio_user_videos.php

                         

                        Regards


                        Dominic

                        • 9. Re: Help with PHP FMstudio - adding a script to button
                          Gingernut

                          I am not too sure what the session bits are doing

                           

                          With them just like this Where No = Jobsheet Number field name, it is not working at all so for the moment have commented out these two lines and I am being served the correct data (from the previous page)

                           

                          with them in i get nothing

                          I am not sure how the php in this page knows what database etc to use ( think that may be the problem or I am barking up completely the wrong tree)

                           

                          Please be patient with me sure we are nearly there

                           

                          $_SESSION['currentRecordID'] = $record->getRecordId();

                          $_SESSION['currentJobNo'] = $record->getField(No);

                          • 10. Re: Help with PHP FMstudio - adding a script to button
                            Gingernut

                            this is my page as it is and it is the session bits that I am failing to follow and therefore have wrong I think

                            <?php require_once('Connections/Jobsheet.php'); ?>

                            // I added this in case it might help

                            //Do I need the session on previous page that landed me on this page?

                            <?php

                            session_start();

                            $Jobsheet_find = $Jobsheet->newFindCommand('@Jobsheet');

                            $Jobsheet_findCriterions = array('No'=>'=='.fmsEscape($_REQUEST['JSNumber']),);

                            foreach($Jobsheet_findCriterions as $key=>$value) {

                                $Jobsheet_find->AddFindCriterion($key,$value);

                            }

                             

                            fmsSetPage($Jobsheet_find,'Jobsheet',10);

                             

                            $Jobsheet_result = $Jobsheet_find->execute();

                             

                            if(FileMaker::isError($Jobsheet_result)) fmsTrapError($Jobsheet_result,"error.php");

                             

                            fmsSetLastPage($Jobsheet_result,'Jobsheet',10);

                             

                            $Jobsheet_row = current($Jobsheet_result->getRecords());

                             

                            //$_SESSION['currentRecordID'] = $record->getRecordId();

                            //$_SESSION['currentJobNo'] = $record->getField(No);

                             

                             

                            // FMStudio v1.0 - do not remove comment, needed for DreamWeaver support ?>

                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                            <html xmlns="http://www.w3.org/1999/xhtml">

                            <head>

                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

                            <title>Untitled Document</title>

                            <link media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" rel="stylesheet" />

                            <link media="screen" href="iphone.css" type="text/css" rel="stylesheet" />

                            </head>

                            <body>

                            <p> <a href= "/jobsheets/jobStatus.php?action=accept">

                              <input name ="Accept" type ="button" value="Accept"/>

                            </p>

                            <table width="614" border="0">

                              <tr>

                                <td width="183"><?php echo $Jobsheet_row->getField('Name',0); ?></td>

                                <td width="190"><?php echo $Jobsheet_row->getField('AccNo'); ?></td>

                                <td width="219" bgcolor="#FFFF00"><?php echo $Jobsheet_row->getField('CallAcceptedTime'); ?></td>

                              </tr>

                              <tr>

                                <td><?php echo $Jobsheet_row->getField('Machine',0); ?></td>

                                <td><?php echo $Jobsheet_row->getField('SerialNo',0); ?></td>

                                <td><?php echo $Jobsheet_row->getField('Location',0); ?></td>

                              </tr>

                              <tr>

                                <td colspan="3"><?php echo $Jobsheet_row->getField('Address'); ?></td>

                              </tr>

                              <tr>

                                <td> </td>

                                <td> </td>

                                <td> </td>

                              </tr>

                             

                            .

                             

                            </body>

                            </html>

                            • 11. Re: Help with PHP FMstudio - adding a script to button
                              steve.winter

                              Howdy

                               

                              Where you have

                               

                              $Jobsheet_result = $Jobsheet_find->execute();

                               

                               

                              if(FileMaker::isError($Jobsheet_result)) fmsTrapError($Jobsheet_result,"error.php");

                               

                               

                              fmsSetLastPage($Jobsheet_result,'Jobsheet',10);

                               

                               

                              $Jobsheet_row = current($Jobsheet_result->getRecords());

                               

                               

                              //$_SESSION['currentRecordID'] = $record->getRecordId();

                               

                              //$_SESSION['currentJobNo'] = $record->getField(No);

                               

                               

                              Try using

                               

                              $_SESSION['currentRecordID'] = $Jobsheet_row->getRecordId();

                              $_SESSION['currentJonNo'] = $Jobsheet_row->getField('No');

                               

                              If that doesn't work, what errors are you getting…??

                               

                              What happens when you try clicking on the button, and loading jobStatus.php…?

                               

                              If you're really stuck, I could set up a quick screen-sharing session and explain how my suggestions works, plus get it working with you…??

                               

                              Cheers

                              Steve

                              • 12. Re: Help with PHP FMstudio - adding a script to button
                                Gingernut

                                There are no rows as it is only one record that will be found on the detail screen

                                 

                                The error arises coming from the previous page which was the Array of jobsheets for AK for eg From the array he clicks one jobsheet and goes to the detail page Jobsheet_1.php which is where I want the button.

                                 

                                In other words (or same words again) There is only one record on the page that the button is to act on.

                                 

                                I am not getting as far as the status with the session lines active in the Jobsheet_1 page because it is not giving me any data at all.

                                 

                                If you could do a screensave that would be FAB. I use teamviewer but can connect to whatever you suggest.

                                 

                                I am so grateful for your help.

                                 

                                Cathy

                                • 13. Re: Help with PHP FMstudio - adding a script to button
                                  Gingernut

                                  Apolgies should have known you knew better - that works but still not setting the field when I click accept

                                  What are your trianing rates per day email me if you offer training services

                                  cathy@clarity-copiers.co.uk