How do I populated a field with another field automatically?

Archived from the Xataface Users forum.

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?


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'));    } }

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.


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).


rlevin — Fri Jul 15, 2011 10:48 am

Thank you!