Jump to content

Checkbox


LeslieC
 Share

Recommended Posts

Hey guys,

This is probably a stupid question, but how do I add options to custom field checkbox ???

Normally when you have checkbox you can add option like red,blue,green,.... so you can select the option you like, but I cant figure out where to add the options  :-X

Thanks

Leslie

Link to comment
Share on other sites

At fields

Add New Field -> Type -> Checkbox and you can name it what ever you want

and in template you can set up which checkbox to show

Find 3 of the most recent children that have a red checkbox set, and display links to them:

    

<?php $red= $page->children("red=1, limit=3, sort=-date");
    foreach($red as $redcolor)
        echo "<p>Red Color: <a href='{$redcolor->url}'>{$redcolor->title}</a></p>";  
Link to comment
Share on other sites

Here is the recommended way to do this in ProcessWire (using your example):

1. Create a page: /options/favorite-foods/ (for example). Though call it whatever you want and place it wherever you want.

2. Add child pages:

  • /options/favorite-foods/chocolate
  • /options/favorite-foods/pizza
  • /options/favorite-foods/gum
  • /options/favorite-foods/waffles
  • /options/favorite-foods/ice-cream
  • /options/favorite-foods/donuts
  • /options/favorite-foods/chips

3. Add a new "Page" reference field in Setup > Fields.

  • Call it 'favorite_foods' (or whatever you want)
  • For 'Dereference in API as', choose 'Multiple Pages'
  • For 'Parent of selectable pages' select '/options/favorite-foods/'
  • For 'Input field type' choose 'Checkboxes'

4. Add the new favorite_foods field to whatever templates you want, and you are set.

More info:

Need to add a new option? Add a new page under /pages/favorite-foods/

Want to do something cool with the template your favorite foods are using? Add this:

<?php
$links = $pages->find("favorite_foods=$page"); 
echo $links->render(); 

That would list all pages that had that particular favorite food selected. Perhaps this is a useful page in your site?

Once you get used to the power of creating options this way, you won't want to do it any other way. :)

 

  • 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...