Testing, getting and setting checkbox values

Archived from the Xataface Users forum.

Martin Dowse — Fri Aug 06, 2010 3:20 pm

Hi

what is the recommended way of testing, getting and setting values stored in widget:type=checkbox fields? Is there a way to use $record->valueChanged, $record->val and $record->setValue with individual fields within the checkbox array?

Thanks

Martin

PS: Apologies if this post turns up twice - I thought I had posted it last night but I can’t see it now so here it is again.


shannah — Wed Aug 11, 2010 10:44 am

I always forget exactly how they’re stored… I think these fields are stored as associative arrays. The best way to check is to do a print_r on output of the val() method for the particular field.
e.g.

Code: Select all
print_r($record->val('my_checkbox_field'));

The valueChanged() method will return true if ANY of the values have changed. You can compare the changes by comparing getSnapshot() with getValues().

e.g.

Code: Select all
$snapshot = $record->getSnapshot(); $current = $record->getValues(); $oldFieldVal = $snapshot['my_field']; $currFieldVal = $current['my_field'];

or something along those lines.

-Steve


Martin Dowse — Wed Aug 11, 2010 12:51 pm

Thanks - that will do the job.