2 Replies Latest reply on Aug 2, 2016 11:50 AM by carmean

    Auto enter a date for a new record via web PHP api: Date format YYYY/MM/DD

    carmean

      Workers submit a new timesheet online every other week.  The timesheet (addrecord.php) auto-enters the 'Current Pay Period' (Period Ending) but workers must be able to change the date.

       

      The best way I know to auto-enter a value for a new record is through a valuelist (our secretary changes the value every pay period).  (Anything else would require a person to create the record first and then get the value through a relationship, at least in my limited experience).

       

      I have used this code for years and it works very well:

       

      getField('Period Ending', 0) ; ?> getValueListTwoFields('Timesheet Period Ending Date', (isset($master_record)) ? $master_record->getRecordId() : $record->getRecordId()), $fieldValue, getFieldFormName('Period Ending', 0, $record, true, 'RADIOBUTTONS', 'text'), 'text', $submitDateOrder);?> is the ending date for the Current Pay Period.

       

      It appears like this:

      2-Week Period Ending (MM/DD/YYYY):07/16/2016 is the  Current Pay Period.
      However I want to change our date format to YYYY/MM/DD, which I have done and it works well for all the other date fields.
      When I change the date format all the other date fields work well,
      2-Week Period Ending (YYYY/MM/DD):2016/08/13 is the Current Pay Period.
      but this field is only accepted if I change it to MM/DD/YYYY format.  I have modified fmview.php
      I figured out how to grab the date via PHP, which allows us a lot more flexibility...

      ANSWER:

      <?php

      $layoutObject = $fm->getLayout($layoutName);

      $fieldName = "Period Ending";

       

      //GET THE FIELD FROM LAYOUT AS AN OBJECT

      $fieldObject = $layoutObject->getField($fieldName);

       

      //GET THE VALUE LIST ATTACHED TO THIS FIELD

      $valueList = $fieldObject->getValueList();

      $periodend = array_shift(array_slice($valueList, 0, 1));

      ?>

       

      <?php displayDate( $record->getField('Period Ending', 0) , $displayDateFormat) ; ?>

      <input size="16" id="datepickerperiod" name="<?php echo getFieldFormName('Period Ending', 0, $record, true, 'EDITTEXT', 'date');?>"

      value="<?php echo $periodend;?>" type="text"> <?php echo $periodend;?> is the ending date for the Current Pay Period.

      Any suggestions for improving are welcome!

      Filemaker 11 & 12 server, Apache/ OS X.