Set default value based on previous entry

Archived from the Xataface Users forum.

gbyerly — Sat May 14, 2011 6:32 am

The user is adding new records, all of which will have the same value for the date field. After the user enters each record, I use code found here to automatically take the user the the data entry screen for another new record. I would like to set the default value of the date field to be equal to the value of the date entered on the previously saved record. How can I do that without duplicating the record and wiping out the other fields (the user may have finished entering records so I don’t want to add the next record; I just want to set the date’s default value based on the last record entered)?


shannah — Sat May 14, 2011 9:22 am

What strategy are you using for directing the user directly to the new record form after inserting a record? If you are using the after_action_new trigger, then you can just add the date as a parameter to the URL to the new record form, and it will use it as the default value… e.g.

Code: Select all
function after_action_new($params){     $record = $params['record'];     $query = Dataface_Application::getInstance()->getQuery();     header('Location: '.DATAFACE_SITE_HREF.'?-table='.urlencode($query['-table']).'&-action=new&mydatefield='.urlencode($record->strval('mydatefield')));     exit; }

This example assumes that your date field is named ‘mydatefield’

-Steve


gbyerly — Sat May 14, 2011 9:49 am

Perfect! Thanks for your speedy response.