Jump to content

how to use checkbox

Recommended Posts

Hi. I am new on processwire. 

I want to add checkbox fields to my page  edit and when if they are selected. I want to show the text in the front page.

I couldnt find where i can enter the value of checkbox   and how to show in theme ?

Can you give me a small example ? 

I took the snap from this video ( http://processwire.com/videos/field-dependencies/ ) i want to do smilar.   thank you


Share this post

Link to post
Share on other sites

It's in the page tree.

Selects and Checkboxes are infact pages (Fieldtype Page). 

For the page references, select the options page as parent. Look at the page tree below. 

options ( options template )
  +-- option one ( option template )
  +-- option two ( option template )
  +-- option three ( option template )

  • Like 2

Share this post

Link to post
Share on other sites

It actually depends a bit whether you want a single checkbox, or an array of checkbox items to choose from. The former is simply a matter a creating a field of type checkbox. The latter is what Martijn is talking about and requires creating a pagefield.

  • Like 2

Share this post

Link to post
Share on other sites

Do you want to control the display of your pages with a checkbox? That means, if you assign the checkbox in a page, this page will be shown in the frontend?

Or do you want control specific elements (like body, title...) of your page?

Share this post

Link to post
Share on other sites

my question is very simple.

I want to make a one checkbox and if this checkbox is checked i want to show some text in the page ...

But i couldnt find  where i can enter that text when i create a checkbox in the fields. and how to show in the template.  i need very simple example for understanding.

My checkbox name is :  check

İ added this to template : 

<?php echo $page->check; ?>

and when i checked its show :  1   

but how i can show a text ?

Share this post

Link to post
Share on other sites


if ($page->check == 1) // 1 is checked, 0 is unchecked

echo "some text";

echo $page->sometextfield;


  • Like 6
  • Thanks 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By louisstephens
      Is it possible to use count() to return a number of repeater items don't have a checkbox checked? In my current set up, I have a repeater on the page "dev_repeater" with a checkbox called "dev_repeater_exclude". I need to get a count of the current items that do not have it checked so I can pass it to my css grid to alter the column width.
    • By Chris Bennett
      Not sure where I originally saw it while lurking around the forums, but someone, somewhere at some time was asking about styling Uikit checkboxes as toggle-style switches, much like the ones at the bottom of this post asking me if I want to be notified of replies.
      So here is my humble offering, rough and ready,  which can be thrown in at the bottom of your Uikit css as a starting point.
      Everything is based on ems and rems, so you can increase size as you desire by altering the single instance of font-size.
      It only targets single instances of labels within a specific field to a) try to limit unintended consequences and b) because in those cases it often seems more user-friendly to have an on/off binary switch rather than a checkbox. It's still totally a checkbox, just styled differently.
      .uk-form-controls-text label:only-of-type input.uk-checkbox { font-size:.8rem; margin-top:0; position:relative; -webkit-appearance:none; outline:none; width:4em; height:2.4em; border:2px solid #D6D6D6; border-radius: 3em; box-shadow:inset 5em 0 0 0 #DDD; flex-shrink: 0; } .uk-form-controls-text label:only-of-type input.uk-checkbox:after { content:""; position:absolute; top:.25em; left:.25em; background:#FFF; width:1.6em; height:1.6em; border-radius:50%; transition:all 250ms ease 20ms; box-shadow:.05em .25em .5em rgba(0,0,0,0.2); } .uk-form-controls-text label:only-of-type input.uk-checkbox:checked { background-color: transparent; box-shadow:inset 5em 0 0 0 #4ed164; border-color:#67bba5; } .uk-form-controls-text label:only-of-type input.uk-checkbox:checked:after { left:1.85em; box-shadow:0 0 1em rgba(0,0,0,0.2); } label:only-of-type input.uk-checkbox:checked + span { color:#008a00; transition:all 250ms ease 20ms; } .InputfieldCheckbox .InputfieldContent label:only-of-type {display:flex;} label:only-of-type input.uk-checkbox + span { color:#c3c3c3; display:flex; align-items:center; line-height:1.1; } /* Below is only necessary if you want the optional "tick" after items when selected */ label:only-of-type input.uk-checkbox + span:after { flex-shrink:0; margin-left:.5em;width:2em; opacity:0; content:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 250 250'%3E%3Ccircle cx='125' cy='125' r='125' fill='%23231F20' opacity='.1'/%3E%3Cpath fill='%230B8B44' d='M95.823 139.432l-32.492-32.56-31.872 31.883-.008-.008 63.72 63.732L218.549 79.116 187.494 47.52z'/%3E%3C/svg%3E"); } label:only-of-type input.uk-checkbox:checked + span:after { opacity:1; transition: opacity 250ms ease 150ms; }  

    • By Robin S
      Checkbox Reversed
      Modifies InputfieldCheckbox so that it shows the reverse of its true value. The checkbox will be unchecked when the field value is 1 and checked when the field value is not 1.
      The core FieldtypeCheckbox does not have a setting that allows a checkbox to be checked by default. One reason for this is that only a checked field saves a value to the database. An unchecked field does not save "0" to the database, but rather does not save any value for the field at all. Therefore there is no way to distinguish between a new field that has not yet been saved (and therefore could potentially get a default checked state) and a field that has deliberately been saved as unchecked.
      Because of this you sometimes have to use a checkbox in the opposite way than you would like. Suppose your client has requested a checkbox labelled "Bootylicious" that will be checked by default. This isn't possible with FieldtypeCheckbox so instead you have to convince them that a checkbox labelled "Not bootylicious" that is unchecked by default is just as good. This alternative will achieve the same thing, but it's not ideal.
      A solution
      This module doesn't change the limitations of the core checkbox field, but it provides a workaround that allows you to show the checkbox with the desired default state and label. So in the example above you would still name the field "not_bootylicious" (otherwise it could get confusing in your template files) but you can label the field "Bootylicious" and the checkbox will appear checked when its true value is actually unchecked, and vice versa. This allows new pages to show the checkbox checked by default. Clear as mud?
      Install the Checkbox Reversed module.
      For any Checkbox field where you want the inputfield to show the reverse of its true value, activate the "Reverse the checked state of this inputfield?" option in the field settings.

    • By suntrop
      Hi all! I want to sort child-pages by two fields but I don't know if it is possible within one selector or if I have to make two separate queries
      <?php foreach ($page->children('sort=checkbox, sort=-number') as $child): ?> I want to keep 'checked' pages on top and sort them and all following by the 'number' field. The 'checkbox' field is a 
    • By jploch
      this should be easy, but I can't get it to work.
      I have a repeater with events.
      Every event has an option-field with multiple checkboxes.
      To filter the events on the frontend I have a script, that uses the class names to filter the results (an event can have multiple categories).

      Now I just want to add every checked option (title) to use as my class name.
      This is what I have so far, wich only gets the first title.
      foreach($page->events as $event) { $tags = $event->options->title; echo "<div class='size1of2 {$tags}'>"; echo "<img src='{$event->image->url}'>"; echo "{$event->text_editor}"; echo "</div>"; }
      I know there is an example with a foreach, but how would I use it in this context?
      foreach($page->countries as $country) { echo "<li>$country->title</li>"; }
  • Create New...