Set default value based on previous entry

A place for users and developers of the Xataface to discuss and receive support.

Set default value based on previous entry

Postby 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)?
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm

Re: Set default value based on previous entry

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Set default value based on previous entry

Postby gbyerly » Sat May 14, 2011 9:49 am

Perfect! Thanks for your speedy response.
gbyerly
 
Posts: 21
Joined: Sun Apr 03, 2011 7:12 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 24 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved