Jump to content

select options field type


picarica
 Share

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

1=facebook
2=twitter
3=instagram
4=youtube
5=github
6=linkedin

 

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';
        break;
    case 'twitter':
        ...

 

 

 

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...