ZionBludd Posted May 16, 2018 Posted May 16, 2018 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>
dragan Posted May 16, 2018 Posted May 16, 2018 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. 2
ZionBludd Posted May 16, 2018 Author Posted May 16, 2018 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?
dragan Posted May 16, 2018 Posted May 16, 2018 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>"; } 1
ZionBludd Posted May 16, 2018 Author Posted May 16, 2018 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?
dragan Posted May 16, 2018 Posted May 16, 2018 I don't really understand your question. Please explain "directly" and "field type"? PW inputfield types? 1
ZionBludd Posted May 16, 2018 Author Posted May 16, 2018 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
louisstephens Posted May 16, 2018 Posted May 16, 2018 I believe you would still have to foreach through the options like: foreach($page->name_of_select as $option) { echo "<li>$option->title</li>"; }
ZionBludd Posted May 17, 2018 Author Posted May 17, 2018 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: 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now