Jump to content

"Select" field


Alexander
 Share

Recommended Posts

Hi again, I have another dummy question about Select field use.

I made the field "boardbasis" with select options:

1:=Breakfast

2:=Catered

3:=Self-catered

In template I use $page->boardbasis to extract result from "boardbasis" Select field.

As a result I get on page "1 or 2 or 3" (just pointed numbers).

What should I do achieve as a result "Breakfast or Catered"?

Thanks a lot for your assistant.

Have a great weekend,

a.

Link to comment
Share on other sites

Try $page->boardbasis->name or $page->boardbasis->title if only one selection can be made at time. If multiple pages can be selected, you'll have to foreach through $page->boardbasis (which'll be PageArray in that case) or do something like $page->boardbasis->eq(0)->title.

When echoing out $page->boardbasis, selected page is returned and rendered as numeric ID.

Link to comment
Share on other sites

When echoing out $page->boardbasis, selected page is returned and rendered as numeric ID.

<quick tut>

And in case you are wondering why this is so...it is no mystery. Look under the hood in your PW database. Select one of your Page Reference Fields db tables (e.g. field_boardbasis). You will see the data stored there is/are the page(s) id(s) of the currently selected page(s) - see attached screenshot. And in case anyone else is still wondering why the ID? Well, with the ID, you can get all sorts of information about a page since the ID is unique - unlike custom fields like title :)

</quick tut>

post-894-0-18388800-1371200812_thumb.png

Link to comment
Share on other sites

When you create the field, you have radio buttons to choose whether it is a Single Page or a Multiple Page field. When editing the field, this is under BASICS. Also, check under  INPUT when editing the field, scroll down to input field type*. Make sure to make a selection that matches Single Page if your field is for single pages or Multiple Page if it is for multiple pages.Otherwise, you will get no output if you select the wrong type.

Edit: I think some people live right here in these forums ;) Late again!

Edited by kongondo
Link to comment
Share on other sites

This method is different from what we normally use for select options. As you can guess from the responses, we use page fields to build selects and the options are  actual pages. http://processwire.com/videos/page-fieldtype/ This allows for much more flexible and dynamic building as the options are coming from pages.

The select field you're using is completely different as you have options hardcoded into the field, you could just hardcode the labels in your template too. You know which key has which value. Or to make things simpler you could use the inputfield interface of the select field to get the options..

$options = $fields->selectfieldname->getInputfield($page)->getOptions();
echo $options[$page->selectfieldname];
  • Like 2
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...