We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33969
    • 60 Posts
    I am setting up my CMP using migxDB. In one of the text fields in the FormTabs I wanted to make the default value the current year. I tried putting
    @EVAL return date('Y');
    , so the year will automatically update, in the 'Input Option > Default Value' box - but I couldn't get that to work.

    The only way I could get it to work was with
    @CHUNK defaultYear
    and putting the EVAL code in the Chunk. That worked - but look 'clunky'. Is there a better way of running code within the 'Input Option > Default Value' box?
      Michael Regan
      TIMR Web Services
      Phone: 250.218.5284
      Eamil: [email protected]
      Website: timr.ca
      • 4172
      • 5,888 Posts
      you could use a aftergetfields - hook - snippet
      with

      if ($object) {
          $record_fields = $object->get('record_fields');
          $year = $object->get['year'];
          $record_fields['year'] = empty($year) ? date('Y') : $year; 
          $object->set('record_fields',$record_fields);
      }
      
      return '';
      [ed. note: Bruno17 last edited this post 11 years, 3 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 33969
        • 60 Posts
        Thanks -

        I couldn't get that snippet to run properly. I dumped the $records in 'processors/mgr/default/fields.php' and the 'year' field had been set. But, it didn't display in the input box or get saved to the database when I saved the entry with the year field empty.

        Using the @CHUNK does work - so I am not too concerned.

          Michael Regan
          TIMR Web Services
          Phone: 250.218.5284
          Eamil: [email protected]
          Website: timr.ca
          • 4172
          • 5,888 Posts
          there was a mistake in the snippet.
          This was wrong:

          $year = $record->get['year'];
          


          needs to be

          $year = $object->get['year'];
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!