How do I populated a field with another field automatically?

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

How do I populated a field with another field automatically?

Postby rlevin » Fri Jul 15, 2011 10:25 am

My problem seems relatively simple, if fieldB == "", then fieldB == fieldA.

Correct me if im wrong but in my case I would use beforesave(). When I click save I want to check if the textbox value for fieldB is empty. If so, set the textbox value of fieldA to the fieldB field. How do I reference the textbox value of those fields?
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: How do I populated a field with another field automatically?

Postby shannah » Fri Jul 15, 2011 10:33 am

Yes. the beforeSave() hook sounds like the right place for this:
Code: Select all
function beforeSave($record){
   if ( !$record->val('fieldA') ){
      $record->setValue('fieldA', $record->val('fieldB'));
   }
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How do I populated a field with another field automatically?

Postby rlevin » Fri Jul 15, 2011 10:41 am

I dont know why but I was assuming record->val('fieldA') looked at the value within the database not the textbox itself.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: How do I populated a field with another field automatically?

Postby shannah » Fri Jul 15, 2011 10:47 am

The $record parameter passed to beforeSave is a Dataface_Record object. Its values at that time include any unsaved changes (i.e. any data entered from an edit form).
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How do I populated a field with another field automatically?

Postby rlevin » Fri Jul 15, 2011 10:48 am

Thank you!
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 4 guests

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