Jump to content

select options field type


Recommended Posts

so i made some options in t he field type, and i want to check if selected title is that output this is my sample code

                                if($media->r_soc == 'facebook') {
                                    $soc = 'facebook';
                                } elseif($media->r_soc == 'twitter') {
                                    $soc = 'twitter';

i just basically want to check if the user in CMS selected option facebokk and then outpit it into variable which is later outputted into fa icon, oh and also this is all in repeat field

                            foreach($ikonky as $media) {

so thats why its $media, but as of now it outputs blank state, not sure why,

it doesnt outpit anything none of the check goes throught these are options i have in the field



Link to comment
Share on other sites

If I understand you correctly, you are using a select option field.

Looping through the selected options is described at https://processwire.com/docs/fields/select-options-fieldtype/#outputting-selected-options-on-a-page

You could then use if statements to test with something like this:

if ($media->title == 'facebook' {

Or a switch statement might be neater if there are several options:

switch ($media->title) {
    case 'facebook':
        $soc = 'facebook';
    case 'twitter':




Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...