WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Checkboxes and functions.php (2 posts)

  1. St0nee
    Member
    Posted 2 years ago #

    Hi all,
    I want to make a filter using checkboxes that would allow users to filter articles by ticking one or multiple checkboxes, each checkbox representing a specific tag.

    For Example:

    <form action="<?php get_the_selected(); ?>" method="post">
    <input type="checkbox" name="selections[]" value="tag1" />Select1<br />
    <input type="checkbox" name="selections[]" value="tag2" />Select2<br />
    <input type="checkbox" name="selections[]" value="tag3" />Select2<br />
    <input type="submit" name="formSubmit" value="Submit" />
    </form>

    This is just an example, I am using like 20 or more checkboxes..
    Now when you check one or two or three chechboxes and click submit button, I want to make the function that would generate a tag link like this:
    site_url/?tag=tag1+tag2+tag3
    or tag1+tag2
    or tag1.. depending on the selection...

    I was searching the web and found something that I thought would work
    here.

    But the problem is that this tutorial isn't done using wordpress.. And when I try to add function in functions.php

    function get_the_selected() {
     $allselected = $_POST['selections'];
      if(empty($allselected))
      {
        echo("You didn't select anything.");
      }
      else
      {
        $N = count($allselected);
        echo("You selected $N: ");
        for($i=0; $i < $N; $i++)
        {
          echo($allselected[$i] . " ");
        }
      }
    }

    It's not working.. to be precise, even when I check some boxes, I still get that I didn't check any.. I know that this function probably would not achieve my desired result, but for now I would like to just make it so it could correctly detect my checked boxes...
    This is the first time I am doing something like this... :)

    Also, when I created checkbox-form.php file and put all the code.. it detected everything fine.. So I think that this function needs only some minor adjustments, but the lack of my skill prevents me from writing the correct function

    So, could anyone help me make the correct function ? I hope you understoon what I'm after. I would really appreciate any thoughts, suggestions, ideas :)

    Thank you in advance,
    St0nee

  2. St0nee
    Member
    Posted 2 years ago #

    got it. :)

Topic Closed

This topic has been closed to new replies.

About this Topic