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.

Multiple Dynamic Parameters that are the same

November 11, 2012 8:51pm

Subscribe [3]
  • #1 / Nov 11, 2012 8:51pm

    xdupChook

    9 posts

    Hello,

    I have a form setup where users can select multiple checkboxes, but when I try to test it, only the last input is actually shown on my search results page (I want to make it so that it brings back everything that’s checked). Clearly I’m doing something wrong, so hopefully someone can chime in? Thanks in advance. =]

    Here is my form:

    <form method="post" action="{path='main/searchresults'}">
     <input type="submit" value="Go!" />
      <ul>
       <li>
        <input id="Beef" name="search:meat" type="checkbox" value="Beef"><label for="Beef">Beef</label>
       </li>
       <li>
        <input id="Chicken" name="search:meat" type="checkbox" value="Chicken"><label for="Chicken">Chicken</label>
       </li>
       <li>
        <input id="Pork" name="search:meat" type="checkbox" value="Pork"><label for="Pork">Pork</label>
       </li>
      </ul>
    </form>

    Here is my channel entries tag:

    {exp:channel:entries channel="recipes" dynamic_parameters="search:meat"}
     {body}
    {/exp:channel:entries}
  • #2 / Nov 11, 2012 10:59pm

    xdupChook

    9 posts

    So after diving deep into the internet, I found a solution to my problem using PHP string concatenation. However, I’m wondering if there is a way to do so without PHP. Here’s my modified code:

    Search Form:

    <form method="post" action="{path='main/searchresults'}">
     <input type="submit" value="Go!" />
      <ul>
       <li>
        <input id="Beef" name="meat[]" type="checkbox" value="Beef"><label for="Beef">Beef</label>
       </li>
       <li>
        <input id="Chicken" name="meat[]" type="checkbox" value="Chicken"><label for="Chicken">Chicken</label>
       </li>
       <li>
        <input id="Pork" name="meat[]" type="checkbox" value="Pork"><label for="Pork">Pork</label>
       </li>
      </ul>
    </form>

    Search Result PHP String Concatenation:

    <?php
    $meats = "";
    foreach($_POST['meat'] as $meat){
    $meats .= $meat."|";
    }
    $meats = substr($meats,0,-1);
    ?>

    Search Result Channel Entry:

    {exp:channel:entries channel="recipes" search:meat="<?php echo($bbqs);?>"}
     {body}
    {/exp:channel:entries}
  • #3 / Nov 13, 2012 12:01pm

    Shane Eckert

    7174 posts

    Hey xdupChook,

    Thank you for your question.

    Can I ask what it is that you are trying to accomplish without using the search module? Just curious.

    I can point out two things that I notice. For the value to come through for your array, you need to add a pipe. Like a so.

    <input id="Beef" name="meat[]" type="checkbox" value="Beef|"><label for="Beef">Beef</label>

    But also, the channel entries search will not search checkboxes. :-(

    Note: Only fields of the type “Text Input”, “Textarea”, and “Drop-down Lists” are searched with this parameter.

    You could use a drop down on the backend and present it as checkboxes on the front end, but that’s a restriction to be aware of.

    I will be on the lookout for your response.

    Cheers,

     

  • #4 / Nov 14, 2012 8:03pm

    xdupChook

    9 posts

    Hi Shane,

    I would actually like to use the search module, as I don’t think pagination works using the approach I am currently taking (I also couldn’t really figure it out because users wouldn’t actually be typing keywords to search).

    Basically what I’m doing is building a database that I will be continuously adding to. I’m using the recipes thing as a way to test if it works (and it also follows a similar model to what I’m doing). What I would be doing is treating entries as the recipe itself. Users on the site will have a series of options to choose from (eg. meat, vegetables, gluten-free, etc) that will all be custom channel fields. When users check different boxes under these categories, such as ‘beef’ under meat, the site should filter out all those entries that do not include beef and return only those that do. I want users to be able to add additional parameters, so that they can get exactly what they want based on the filters they use.

    Thanks.

    Bryan

  • #5 / Nov 15, 2012 2:23am

    DigitalDoctors

    76 posts

    Slightly off topic, but take a look at the PHP implode method - http://php.net/manual/en/function.implode.php

    eg:

    $meats = implode('|', $_POST['meat']);
  • #6 / Nov 16, 2012 3:47pm

    Dan Decker

    7338 posts

    Hi Brian,

    Check out Tag from Solspace. I think it is built for just this purpose.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases