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.

Search Form Help

October 05, 2012 2:27pm

Subscribe [2]
  • #1 / Oct 05, 2012 2:27pm

    DanL posted an interesting way to do a dropdown-based entries search that I just can’t get to work. The post can be found here.

    Here’s my code:

    <form method="post" action="#">
    TYPE
    
    <select name="types">
    <option value="">Select All</option>
    <option value="Type 1">Type 1</option>
    <option value="Type 2">Type 2</option>
    </select>
    
    LOCATION
    
    <select name="locations">
    <option value="">Select All</option>
    <option value="Urban">Urban</option>
    <option value="Rural">Rural</option>
    </select>
    
    BEDROOMS
    
    <select name="bedrooms">
    <option value="">Select All</option>
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    
    <input type="submit" src="/images/interface/submit.gif" border="0" alt="Submit">
    </form>
    
    {exp:channel:entries channel="property" search:house_type="{embed:types}" search:house_location="{embed:locations}" search:house_bed="{embed:bedrooms}"}
    {title}
    
    {/exp:channel:entries}

    This is my first time trying this sorting method, so I know I am missing something. Any help is greatly appreciated.

    Thanks everyone!

  • #2 / Oct 08, 2012 5:38am

    DanL

    56 posts

    You’re almost there - it’s not clear if this is the actual template you are trying to use or if you’re just showing snippets of code - but you can’t just plug-in the {embed} buts like that - they must be assigned when embedding a sub-template.

    For example, I use this technique here:

    http://www.encompassed.co.uk/courses/public-training-courses

    The table content is a separate template which is called on the main page after the form.  You’ll also need some PHP to call the variables from $POST:

    <?php // Set up POST variables:
    if( isset($_POST['name_of_course']) ) { $course_name_select=$_POST['name_of_course']; } else { $course_name_select="all"; }
    
    if( isset($_POST['location']) ) { $location_select=$_POST['location']; } else { $location_select="all"; }
    
    ?>
    
    <form>
    ...
    </form>
    
    {!-- CALL THE SUB-TEMPLATE --}
    {embed="includes/_my_table_output" name_of_course="<?php if($course_name_select !== "all") {echo $course_name_select;} ?>" location="<?php if($location_select !== "all") {echo $location_select;} ?>"}

    Then the sub-template takes the embedded variables like this:

    {exp:channel:entries channel="courses" dynamic="off" orderby="date_of_session" sort="asc" search:training_session_location="{embed:location}" search:course_name="{embed:name_of_course}"}

    ...so you see the {embed:variable_name} bits can only be used in a separate template when using the {embed="name_of_template"} feature.

    Hope that helps you figure out the rest!

    Cheers
    Dan

  • #3 / Oct 08, 2012 10:43am

    Ahhhhhh, I get it!

    Big thanks DanL. :coolsmile:

  • #4 / Oct 08, 2012 10:45am

    DanL

    56 posts

    No worries my friend - hope you sort it out 😊

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

ExpressionEngine News!

#eecms, #events, #releases