Support » Fixing WordPress » Checkboxes and functions.php

  • Resolved St0nee


    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" />

    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:
    or tag1+tag2
    or tag1.. depending on the selection…

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

    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'];
        echo("You didn't select anything.");
        $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,

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Checkboxes and functions.php’ is closed to new replies.