5 Replies Latest reply on Aug 21, 2012 2:10 PM by Mike_Mitchell

    CWP PHP and value list

    khardy.dsi

      I have a very simple database that I use CWP to log users in and out of thier desk. I have two fields (In or Out, Will Return) both have simple fixed value lists attached to then. I can locate the php functions for the value list (getValueListTwoFields) but cannot locate how to implement the list on the CWP page. I have attached the php file from the sample that i have modified to produce my page. I am seeking assistance on how to display the choices on the website.

       

       

      <html>

      <?php

      /**

      * viewRecord.php

      *

      * Copyright © 2005-2006, FileMaker, Inc. All rights reserved.

      * NOTE: Use of this source code is subject to the terms of the FileMaker

      * Software License which accompanies the code. Your use of this source code

      * signifies your agreement to such license terms and conditions. Except as

      * expressly granted in the Software License, no other copyright, patent, or

      * other intellectual property license or right is granted, either expressly or

      * by implication, by FileMaker.

      *

      * Example PHP script to illustrate how to view a particular record in a database using PHP API.

      *

      * Requirements:

      * 1. Working FileMaker Server installation

      * 2. 'InOut' database hosted in FileMaker Server

      *

      */

       

      // 22 Include FileMaker API

      require_once ('FileMaker.php');

       

       

      // Create a new connection to InOut database.

      // Location of FileMaker Server is assumed to be on the same machine,

      // thus we assume hostspec is api default of 'http://localhost' as specified

      // in filemaker-api.php.

      // If FMSA web server is on another machine, specify 'hostspec' as follows:

      // $fm = new FileMaker('InOut', localhost;

      $fm = new FileMaker();

      $fm->setProperty('database', 'InOut');

      $fm->setProperty('hostspec', 'localhost');

      $fm->setProperty('username', 'webuser');

      $fm->setProperty('password', 'webuser');

       

       

      // Since we're passed in recid via param (i.e. viewRecord.php?recid=n), use

      // FileMaker::getRecordById() to directly get record object with recid accessed

      // via $_GET[] array

      $record = $fm->getRecordById('Contact Status', $_GET['recid']);

       

       

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

      echo "<body>Error: " . $record->getMessage(). "</body>";

      exit;

      }

      // 46 Script to call in status

      $instatus = $fm->newPerformScriptCommand('Contact Status', 'Status to In');

      // $result = $newPerformScript->execute();

      $scripts = $fm->listScripts();

      ?>

      </title>

      <!-- declare charset as UTF-8 -->

      <meta http-equiv="content-type" content="text/html; charset=UTF-8">

      <link rel="stylesheet" href="style2.css">

      </head>

      <body>

      <form action="handleForm.php" method="post">

      <table>

      <tr><th id="table-title" colspan="3">Ashe County DSS In/Out</th></tr>

      <tr><th>Last Name</th><td><?php echo $record->getField('Last'); ?></td></tr>

      <tr><th>First Name</th><td><?php echo $record->getField('First'); ?></td></tr>

      <tr><th>Department</th><td><?php echo $record->getField('Department'); ?></td></tr>

      <tr><th>Office Phone</th><td><?php echo $record->getField('Work Phone'); ?></td></tr>

      <tr><th>Status In/Out</th><td><input type="text" size="80" name="Status" value="<?php echo $record != null ? $record->getField('Status') : null; ?>"></td></tr>

      <tr><th>Return Time</th><td><input type="text" size="80" name="Will Return" value="<?php echo $record != null ? $record->getField('Will Return') : null; ?>"></td></tr>

      <tr><th>Notes</th><td><input type="text" size="80" name="Notes" value="<?php echo $record != null ? $record->getField('Notes') : null; ?>"></td></tr>

      <tr><th>Last Updated</th><td><?php echo $record->getField('Status Updated'); ?></td></tr>

       

       

      <tr><td colspan=2>

      <?php

      // output OK (submit) and Cancel buttons

      if ($record != null) {

      // if we're editing a record, submit button is labeled "OK"

      ?>

      <input type="hidden" name="recid" value="<?php echo $record->getRecordId(); ?>">

      <button type="submit" name="action" value="edit">OK</button>

      <?php

      } else {

      // otherwise, submit button is "Create New Record"

       

       

      ?>

      <button type="submit" name="action" value="edit">Create New Record</button>

      <?php

      }

      ?>

      </td></tr>

      </table>

      </form>

      </body>

      </html>

        • 1. Re: CWP PHP and value list
          Mike_Mitchell

          Hello, khardy.

           

          In order to add the value list, you'll need to use the <select> and <option> tags. Since getValueListTwoFields returns an array of choices, you can use a loop to walk over the array and echo out the options, using code something like this:

           

          $willReturnList = getValueListTwoFields('nameOfWillReturnValueList');

          ...

          echo '<select name="willReturn">';

          foreach($willReturnList as $willReturnOption)  {

           

               $willReturnOption = htmlspecialchars($willReturnOption);

               echo '<option value="'.$willReturnOption.'">'.$willReturnOption.'</option>';

           

          }

          echo '</select>';

           

          That code - including the <select> and <option> loop - replaces your text input box.

           

          HTH

           

          Mike

          • 2. Re: CWP PHP and value list
            khardy.dsi

            So i added and modified the information to my code but now am receiving "PHP Fatal error:  Call to undefined function getValueListTwoFields() in C:\inetpub\wwwroot\InOut\viewRecord.php on line 45".  I have posted the new code below. 

             

            <html>

            <?php

            /**

            * viewRecord.php

            *

            * Copyright © 2005-2006, FileMaker, Inc. All rights reserved.

            * NOTE: Use of this source code is subject to the terms of the FileMaker

            * Software License which accompanies the code. Your use of this source code

            * signifies your agreement to such license terms and conditions. Except as

            * expressly granted in the Software License, no other copyright, patent, or

            * other intellectual property license or right is granted, either expressly or

            * by implication, by FileMaker.

            *

            * Example PHP script to illustrate how to view a particular record in a database using PHP API.

            *

            * Requirements:

            *   1. Working FileMaker Server installation

            *   2. 'InOut' database hosted in FileMaker Server

            *

            */

             

            // 22 Include FileMaker API

            require_once ('FileMaker.php');

             

             

             

             

            // Create a new connection to InOut database.

            // Location of FileMaker Server is assumed to be on the same machine,

            //  thus we assume hostspec is api default of 'http://localhost' as specified

            //  in filemaker-api.php.

            // If FMSA web server is on another machine, specify 'hostspec' as follows:

            //   $fm = new FileMaker('InOut', 'http://911server.ashecountygov.com');

            $fm = new FileMaker();

            $fm->setProperty('database', 'InOut');

            $fm->setProperty('hostspec', 'localhost');

            $fm->setProperty('username', 'webuser');

            $fm->setProperty('password', 'webuser');

             

             

             

             

             

             

            // Since we're passed in recid via param (i.e. viewRecord.php?recid=n), use

            // FileMaker::getRecordById() to directly get record object with recid accessed

            // via $_GET[] array

            $record = $fm->getRecordById('Contact Status', $_GET['recid']);

             

             

            $willReturnList = getValueListTwoFields('In or Out');

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

                echo "<body>Error: " . $record->getMessage(). "</body>";

                exit;

            }

            //  46 Script to call in status

            $instatus = $fm->newPerformScriptCommand('Contact Status', 'Status to In');

            // $result = $newPerformScript->execute();

            $scripts = $fm->listScripts();

            ?>

            </title>

            <!-- declare charset as UTF-8 -->

            <meta http-equiv="content-type" content="text/html; charset=UTF-8">

            <link rel="stylesheet" href="style2.css">

            </head>

            <body>

            <form action="handleForm.php" method="post">

            <table>

            <tr><th id="table-title" colspan="3">Ashe County DSS In/Out</th></tr>

            <tr><th>Last Name</th><td><?php echo $record->getField('Last'); ?></td></tr>

            <tr><th>First Name</th><td><?php echo $record->getField('First'); ?></td></tr>

            <tr><th>Department</th><td><?php echo $record->getField('Department'); ?></td></tr>

            <tr><th>Office Phone</th><td><?php echo $record->getField('Work Phone'); ?></td></tr>

            <tr><th>Status In/Out</th><td>

            <?php

             

             

             

             

            echo '<select name="willReturn">';

            foreach($willReturnList as $willReturnOption)  {

                 $willReturnOption = htmlspecialchars($willReturnOption);

                 echo '<option value="'.$willReturnOption.'">'.$willReturnOption.'</option>';

             

             

             

             

            }

             

             

             

             

            echo '</select>';

            ?>

             

             

             

             

            </td></tr>

            <tr><th>Return Time</th><td><input type="text" size="80" name="Will Return" value="<?php echo $record != null ? $record-

             

             

            >getField('Will Return') : null; ?>"></td></tr>

            <tr><th>Notes</th><td><input type="text" size="80" name="Notes" value="<?php echo $record != null ? $record->getField

             

             

            ('Notes') : null; ?>"></td></tr>

            <tr><th>Last Updated</th><td><?php echo $record->getField('Status Updated'); ?></td></tr>

             

             

             

             

            <tr><td colspan=2>

            <?php

            // output OK (submit) and Cancel buttons

            if ($record != null) {

            // if we're editing a record, submit button is labeled "OK"

            ?>

            <input type="hidden" name="recid" value="<?php echo $record->getRecordId(); ?>">

            <button type="submit" name="action" value="edit">OK</button>

            <?php

            } else {

            // otherwise, submit button is "Create New Record"

             

             

             

             

            ?>

            <button type="submit" name="action" value="edit">Create New Record</button>

            <?php

            }

            ?>

            </td></tr>

            </table>

            </form>

            </body>

            </html>

            • 3. Re: CWP PHP and value list
              Mike_Mitchell

              Oops. My bad. Sorry; you need to execute getValueListTwoFields against a layout object. So change this:

               

                   $willReturnList = getValueListTwoFields('In or Out');

               

              to this:

               

                   $layout = $fm->getLayout('nameOfLayoutWhereValueListAppears');

                   $willReturnList = $layout->getValueListTwoFields('In or Out');

               

              Mike

              • 4. Re: CWP PHP and value list
                khardy.dsi

                Close.  I corrected the text. I have confirmed that layout name is 'Contact Status', the field name is 'Status' and the value list used on that layout in that field is 'In or Out'.  No i have no errors but in the table i have the following:  echo'[Dropdown box with the words:  '..$willReturnOption.'] followd by a ; outside the dropdown.  it does not return any values when dropped which should be either In or Out.  Maybe I should attempt a radio button set...lol.  Here is my new code:

                 

                <html>

                <?php

                /**

                * viewRecord.php

                *

                * Copyright © 2005-2006, FileMaker, Inc. All rights reserved.

                * NOTE: Use of this source code is subject to the terms of the FileMaker

                * Software License which accompanies the code. Your use of this source code

                * signifies your agreement to such license terms and conditions. Except as

                * expressly granted in the Software License, no other copyright, patent, or

                * other intellectual property license or right is granted, either expressly or

                * by implication, by FileMaker.

                *

                * Example PHP script to illustrate how to view a particular record in a database using PHP API.

                *

                * Requirements:

                *   1. Working FileMaker Server installation

                *   2. 'InOut' database hosted in FileMaker Server

                *

                */

                 

                // 22 Include FileMaker API

                require_once ('FileMaker.php');

                 

                 

                // Create a new connection to InOut database.

                // Location of FileMaker Server is assumed to be on the same machine,

                //  thus we assume hostspec is api default of 'http://localhost' as specified

                //  in filemaker-api.php.

                // If FMSA web server is on another machine, specify 'hostspec' as follows:

                //   $fm = new FileMaker('InOut', 'http://911server.ashecountygov.com');

                $fm = new FileMaker();

                $fm->setProperty('database', 'InOut');

                $fm->setProperty('hostspec', 'localhost');

                $fm->setProperty('username', 'webuser');

                $fm->setProperty('password', 'webuser');

                 

                 

                // Since we're passed in recid via param (i.e. viewRecord.php?recid=n), use

                // FileMaker::getRecordById() to directly get record object with recid accessed

                // via $_GET[] array

                $record = $fm->getRecordById('Contact Status', $_GET['recid']);

                 

                 

                $layout=$fm->getLayout('Contact Status');

                $willReturnList=$layout->getValueListTwoFields('In or Out');

                 

                 

                 

                 

                 

                 

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

                    echo "<body>Error: " . $record->getMessage(). "</body>";

                    exit;

                }

                //  46 Script to call in status

                $instatus = $fm->newPerformScriptCommand('Contact Status', 'Status to In');

                // $result = $newPerformScript->execute();

                $scripts = $fm->listScripts();

                ?>

                </title>

                <!-- declare charset as UTF-8 -->

                <meta http-equiv="content-type" content="text/html; charset=UTF-8">

                <link rel="stylesheet" href="style2.css">

                </head>

                <body>

                <form action="handleForm.php" method="post">

                <table>

                <tr><th id="table-title" colspan="3">Ashe County DSS In/Out</th></tr>

                <tr><th>Last Name</th><td><?php echo $record->getField('Last'); ?></td></tr>

                <tr><th>First Name</th><td><?php echo $record->getField('First'); ?></td></tr>

                <tr><th>Department</th><td><?php echo $record->getField('Department'); ?></td></tr>

                <tr><th>Office Phone</th><td><?php echo $record->getField('Work Phone'); ?></td></tr>

                <tr><th>Status In/Out</th><td>echo '<select Name="willReturn">';

                 

                 

                foreach($willReturnList as $willReturnOption) {

                 

                 

                          $willReturnOption=htmlspecialchars($willReturnOption);

                          echo '<option value="'.$willReturnOption.'">'.$willReturnOption.'</option>';

                }

                echo '</select>';

                 

                 

                </td></tr>

                <tr><th>Return Time</th><td><input type="text" size="80" name="Will Return" value="<?php echo $record != null ? $record->getField('Will Return') : null; ?>"></td></tr>

                <tr><th>Notes</th><td><input type="text" size="80" name="Notes" value="<?php echo $record != null ? $record->getField('Notes') : null; ?>"></td></tr>

                <tr><th>Last Updated</th><td><?php echo $record->getField('Status Updated'); ?></td></tr>

                 

                 

                <tr><td colspan=2>

                <?php

                // output OK (submit) and Cancel buttons

                if ($record != null) {

                          // if we're editing a record, submit button is labeled "OK"

                ?>

                <input type="hidden" name="recid" value="<?php echo $record->getRecordId(); ?>">

                <button type="submit" name="action" value="edit">OK</button>

                <?php

                } else {

                          // otherwise, submit button is "Create New Record"

                 

                 

                ?>

                <button type="submit" name="action" value="edit">Create New Record</button>

                <?php

                }

                ?>

                </td></tr>

                </table>

                </form>

                </body>

                </html>

                • 5. Re: CWP PHP and value list
                  Mike_Mitchell

                  You need opening and closing PHP tags. Replace this:

                   

                  -----------------------------------------------------------------

                   

                  <tr><th>Status In/Out</th><td>echo '<select Name="willReturn">';

                   

                   

                  foreach($willReturnList as $willReturnOption) {

                   

                   

                            $willReturnOption=htmlspecialchars($willReturnOption);

                            echo '<option value="'.$willReturnOption.'">'.$willReturnOption.'</option>';

                  }

                  echo '</select>';

                   

                  -----------------------------------------------------------------

                   

                  with this:

                   

                  -----------------------------------------------------------------

                   

                  <tr><th>Status In/Out</th><td>

                   

                  <?php

                   

                  echo '<select Name="willReturn">';

                   

                   

                  foreach($willReturnList as $willReturnOption) {

                   

                   

                            $willReturnOption=htmlspecialchars($willReturnOption);

                            echo '<option value="'.$willReturnOption.'">'.$willReturnOption.'</option>';

                  }

                  echo '</select>';

                   

                  ?>

                   

                  -----------------------------------------------------------------

                   

                  Should get you there.

                   

                  Mike