How do I access the checkbox field column value as a PHP array?Checkbox array for days of the weekGet entries from client checked optionsIs it possible to convert plain text array to an unordered list?Searching on multiple checkboxesCraft 3 Custom Field Type with a File UploaderHow do I delete an asset with module or pluginCraft 3: Possible to merge checkbox and text values from a frontend form and put into a plaintext Craft field?How do I use a relation field in an element?What's the difference between `checkboxGroupField` and `checkboxSelectField` in Craft 3?Saving a SuperTable field within a Matrix Field
This day in history III
Dual-national, returning to US the day the US Passport expires; can he check in with airline on Dutch passport but reenter with expiring US passport?
Why do they sell Cat 5 Ethernet splitters if you can’t split the signal?
Dobbs Murder Mystery : A Picture worth 1000 words?
Are there any unpublished Iain M. Banks short stories?
Adopting a feral cat
Examples of simultaneous independent breakthroughs
What do I do with a party that is much stronger than their level?
Telling manager project isn't worth the effort?
Why is の所 used after ドア in this sentence?
Incrementing add under condition in pandas
Why does Canada require mandatory bilingualism in a lot of federal government posts?
If Trump gets impeached, how long would Pence be president?
Composing fill in the blanks
Finding the Maximum of a Continuous Function over a Closed Interval
Sci-fi change: Too much or Not enough
How many oliphaunts died in all of the Lord of the Rings battles?
Do the books ever say oliphaunts aren’t elephants?
Why does the Eurostar not show youth pricing?
Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?
Why didn’t Christianity spread southwards from Ethiopia in the Middle Ages?
How could Nomadic scholars effectively memorize libraries worth of information
What is this 4 sharp symbol and what does it mean?
Copying an existing HTML page and use it, is that against any copyright law?
How do I access the checkbox field column value as a PHP array?
Checkbox array for days of the weekGet entries from client checked optionsIs it possible to convert plain text array to an unordered list?Searching on multiple checkboxesCraft 3 Custom Field Type with a File UploaderHow do I delete an asset with module or pluginCraft 3: Possible to merge checkbox and text values from a frontend form and put into a plaintext Craft field?How do I use a relation field in an element?What's the difference between `checkboxGroupField` and `checkboxSelectField` in Craft 3?Saving a SuperTable field within a Matrix Field
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I can just get that JSON-encoded value as an array in PHP? Any time I try to get the value of the field, I'm getting the entire MultiOptionsFieldData object which isn't desired in this case. I just want that array of checked values that's stored in the corresponding content table column.
I don't want to write any loops. I just want access to that actual column value from my element in PHP.
I don't want to write any additional queries to get that column value either. Surely, there must be a way to get the actual field value for checkbox fields. Right?
modules checkboxes
add a comment |
I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I can just get that JSON-encoded value as an array in PHP? Any time I try to get the value of the field, I'm getting the entire MultiOptionsFieldData object which isn't desired in this case. I just want that array of checked values that's stored in the corresponding content table column.
I don't want to write any loops. I just want access to that actual column value from my element in PHP.
I don't want to write any additional queries to get that column value either. Surely, there must be a way to get the actual field value for checkbox fields. Right?
modules checkboxes
add a comment |
I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I can just get that JSON-encoded value as an array in PHP? Any time I try to get the value of the field, I'm getting the entire MultiOptionsFieldData object which isn't desired in this case. I just want that array of checked values that's stored in the corresponding content table column.
I don't want to write any loops. I just want access to that actual column value from my element in PHP.
I don't want to write any additional queries to get that column value either. Surely, there must be a way to get the actual field value for checkbox fields. Right?
modules checkboxes
I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I can just get that JSON-encoded value as an array in PHP? Any time I try to get the value of the field, I'm getting the entire MultiOptionsFieldData object which isn't desired in this case. I just want that array of checked values that's stored in the corresponding content table column.
I don't want to write any loops. I just want access to that actual column value from my element in PHP.
I don't want to write any additional queries to get that column value either. Surely, there must be a way to get the actual field value for checkbox fields. Right?
modules checkboxes
modules checkboxes
asked 8 hours ago
Benjamin KohlBenjamin Kohl
2161 silver badge10 bronze badges
2161 silver badge10 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
MultiOptionsFieldData
extends PHP's ArrayObject class.
You could get the values from it by casting it to an array like so:
$results = (array)$mofd;
That would give you an array of OptionData
classes. If you really didn't want to loop through them, you could do something like:
$func = static function($ofd)
return $ofd->value;
;
$results = array_map($func, (array)$mofd);
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
add a comment |
Another option for getting the string values as an array after typecasting the MultiOptionsFieldData
object as an array:
$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry->getFieldValue('diningCuisine') ), 'value');
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "563"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f31101%2fhow-do-i-access-the-checkbox-field-column-value-as-a-php-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
MultiOptionsFieldData
extends PHP's ArrayObject class.
You could get the values from it by casting it to an array like so:
$results = (array)$mofd;
That would give you an array of OptionData
classes. If you really didn't want to loop through them, you could do something like:
$func = static function($ofd)
return $ofd->value;
;
$results = array_map($func, (array)$mofd);
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
add a comment |
MultiOptionsFieldData
extends PHP's ArrayObject class.
You could get the values from it by casting it to an array like so:
$results = (array)$mofd;
That would give you an array of OptionData
classes. If you really didn't want to loop through them, you could do something like:
$func = static function($ofd)
return $ofd->value;
;
$results = array_map($func, (array)$mofd);
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
add a comment |
MultiOptionsFieldData
extends PHP's ArrayObject class.
You could get the values from it by casting it to an array like so:
$results = (array)$mofd;
That would give you an array of OptionData
classes. If you really didn't want to loop through them, you could do something like:
$func = static function($ofd)
return $ofd->value;
;
$results = array_map($func, (array)$mofd);
MultiOptionsFieldData
extends PHP's ArrayObject class.
You could get the values from it by casting it to an array like so:
$results = (array)$mofd;
That would give you an array of OptionData
classes. If you really didn't want to loop through them, you could do something like:
$func = static function($ofd)
return $ofd->value;
;
$results = array_map($func, (array)$mofd);
answered 7 hours ago
Brad BellBrad Bell
60.4k4 gold badges56 silver badges120 bronze badges
60.4k4 gold badges56 silver badges120 bronze badges
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
add a comment |
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
Yeah, getting the array of OptionData instances was as close as I got but I was hoping for just the array of string values. Thanks, Brad. I think a method to obtain the raw value on the MultiOptionsFieldData class might be helpful in situations like this. Maybe something like: $entry->getFieldValue('diningCuisine')->rawValue()
– Benjamin Kohl
6 hours ago
add a comment |
Another option for getting the string values as an array after typecasting the MultiOptionsFieldData
object as an array:
$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry->getFieldValue('diningCuisine') ), 'value');
add a comment |
Another option for getting the string values as an array after typecasting the MultiOptionsFieldData
object as an array:
$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry->getFieldValue('diningCuisine') ), 'value');
add a comment |
Another option for getting the string values as an array after typecasting the MultiOptionsFieldData
object as an array:
$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry->getFieldValue('diningCuisine') ), 'value');
Another option for getting the string values as an array after typecasting the MultiOptionsFieldData
object as an array:
$values = ArrayHelper::getColumn(ArrayHelper::toArray( (array) $entry->getFieldValue('diningCuisine') ), 'value');
answered 6 hours ago
Benjamin KohlBenjamin Kohl
2161 silver badge10 bronze badges
2161 silver badge10 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Craft CMS Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f31101%2fhow-do-i-access-the-checkbox-field-column-value-as-a-php-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown