How do I access the checkbox field column value as a PHP array?Checkbox array for days of the weekGet entries...
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
What steps would an amateur scientist have to take in order to get a scientific breakthrough published?
Name These Animals
Why does this RX-X lock not appear in Extended Events?
Assuring luggage isn't lost with short layover
Does dual boot harm a laptop battery or reduce its life?
Will this creature from Curse of Strahd reappear after being banished?
Introducing Tetronogram!
ECDSA: Why is SigningKey shorter than VerifyingKey
Why is the Apollo LEM ladder so far from the ground?
What do I do with a party that is much stronger than their level?
Telling manager project isn't worth the effort?
This day in history III
Irreducible factors of primitive permutation group representation
Is it safe if the neutral lead is exposed and disconnected?
Incrementing add under condition in pandas
Why force the nose of 737 Max down in the first place?
How can Paypal know my card is being used in another account?
How long until two planets become one?
How do I use JSON.generator to generate an unnamed array?
Finding the Maximum of a Continuous Function over a Closed Interval
How many oliphaunts died in all of the Lord of the Rings battles?
Exploiting the delay when a festival ticket is scanned
Japanese reading of an integer
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