Jump to content

Select FieldType output


ZionBludd
 Share

Recommended Posts

Hi, I am wondering if there is a better way to output a field's options

 Currently I am basically adding types as they are required, but I can see the types growing - and wondering if I can call directly from the field?

 <select name="product_type" class="form-control" style="font-size:9pt">
          <option value=""><?php echo $NO_SELECT_PRODUCT; ?></option>
          <option <?php if ($pt == "Starter Kits"){echo 'selected';};?> value="Starter Kits">Starter Kits</option>
          <option <?php if ($pt == "Advanced Kits"){echo 'selected';};?> value="Advanced Kits">Advanced Kits</option>
          </select>

 

Link to comment
Share on other sites

That's a classic use-case for page reference fields.

Create a dedicated page that acts as parent for all your product types. Underneath, create a page for every product option.

Then you can easily foreach($page->children) etc.

  • Like 2
Link to comment
Share on other sites

2 minutes ago, dragan said:

That's a classic use-case for page reference fields.

Create a dedicated page that acts as parent for all your product types. Underneath, create a page for every product option.

Then you can easily foreach($page->children) etc.

Thanks for your reply, can you give me an example of how I might implement this? 

Link to comment
Share on other sites

Create a "settings" template (name it whatever you want). You only need one field: title (or multilang title).

Create a page somewhere. That will only serve as a parent / container page.

Create as many pages underneath this parent page as needed. One page per select option.

Then, in the template you want to build your form, basically do something like

$settings = $pages->get(123)->children; // 123 is the id of the parent page
foreach($settings as $s) {
    echo "<option value='{$s->title}'>{$s->title}</option>";
}


 

  • Like 1
Link to comment
Share on other sites

1 minute ago, dragan said:

Create a "settings" template (name it whatever you want). You only need one field: title (or multilang title).

Create a page somewhere. That will only serve as a parent / container page.

Create as many pages underneath this parent page as needed. One page per select option.

Then, in the template you want to build your form, basically do something like


$settings = $pages->get(123)->children; // 123 is the id of the parent page
foreach($settings as $s) {
    echo "<option value='{$s->title}'>{$s->title}</option>";
}


Thanks, you can't directly output a field type? 

 

Link to comment
Share on other sites

Just now, dragan said:

I don't really understand your question. Please explain "directly" and "field type"? PW inputfield types?

Just curious, if I had a select input by the name of "type" - Can I call that directly and output the options

Link to comment
Share on other sites

18 hours ago, louisstephens said:

I believe you would still have to foreach through the options like:


foreach($page->name_of_select as $option) {
	echo "<li>$option->title</li>";
}

 

Thanks for all of your help. I managed to get the desired end result using Ryan's example: 

 

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...