ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Filtering form in template

June 28, 2011 8:14am

Subscribe [2]
  • #1 / Jun 28, 2011 8:14am

    JusTyMe

    76 posts

    Hi!

    I have a template showing all entries from a channel and I wish to add a filtering form by category something like this.

    <form method="post" action="">
        <input type="checkbox" name="category" value="3"> Category 1
        <input type="checkbox" name="category" value="4"> Category 2
        <input type="checkbox" name="category" value="5"> Category 3
        <input type="submit" name="submit" value="submit">
    </form>

    Is this possible to implement this idea. Once a user will click submit then the choosen categories will only show in the Template?

    I tried this but no luck..

    This is on top of the template

    $cat1 = $this->EE->input->post('cat1');
    $cat2 = $this->EE->input->post('cat2');
    $cat3 = $this->EE->input->post('cat3');
    $categories = "";
            
    if ( $cat1 == "1" ) {
        $categories = $categories . "1";
    } 
        
    if ( $cat2 == "2" ) {
        $categories == "" ? $categories = $categories . "2" : $categories = $categories . "|2";
    }
            
    if ( $cat3 == "3" ) {
        $categories == "" ? $categories = $categories . "3" : $categories = $categories . "|3";
    }

    In the end of the PHP code $categories will be “1|3” if the 1st and 2nd checkboxes are checked.

    I am trying to to this in the channe tag, somthing like this but this won’t work..

    {exp:channel:entries channel="{preload_channel}" category="<?php echo $categories?>"}

    I tried this as well

    {preload_replace:pre_categories="<?php echo $categories?>"}
    {exp:channel:entries channel="{preload_channel}" category="{pre_categories}"}

    My preload_channel is working but my preload_categories wont but I can view it by just simply calling the tag {pre_categories}


    Can anyone help me?

    Thanks…

    [Mod Edit: Moved to the Community Help forum]

  • #2 / Jun 28, 2011 10:26am

    Tom Jaeger

    449 posts

    You should be able to do this; do you have the “PHP Parsing Stage” set to input or output?  I believe you will need it set to input.


    I would try something like this real quick as a proof of concept.

    <?php $categories = '3'; ?>
    {exp:channel:entries channel="{preload_channel}" category="<?php echo $categories?>"}

    -Tom

  • #3 / Jun 28, 2011 10:42am

    JusTyMe

    76 posts

    Thanks Tom!

    But upon changing the PHP parsing to INPUT, all of my codes are showing in the browser already.

    Jay

  • #4 / Jun 28, 2011 10:51am

    Tom Jaeger

    449 posts

    When you mention all of your codes showing in the browser, do you mean your PHP?  If so it almost sounds like “Allow PHP” got set to no.

    -Tom

  • #5 / Jun 28, 2011 11:03am

    JusTyMe

    76 posts

    I found an error at the bottom of my page. I have a PHP there which is not parsing well. It is just strange that it parsed when the parsing stage is OUTPUT.

    Anyway. Thanks for your help Tom. You saved my day.

    - Jay

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases