• Resolved senyoraangelica

    (@senyoraangelica)


    Hello! I’ve been looking for a solution for the past few days but I just couldn’t figure it out. Under echo $pod->filters(); , I echoed some checkboxes from another pod page which will let visitors search my pods through any custom fields they want:

    <form action="" method="get">
    <input type="checkbox" name="bookauthor" checked="checked">
    	<label for="bookauthor">Author</label>
    <input type="checkbox" name="bookyear">
        <label for="bookyear">Year</label></form>

    Then I set my 'where' variables in php.

    $bookauthorfield = array(
                 'key' => 'book_author',
                 'value' => pods_var( 'search' ),
                 'compare' => 'LIKE'
              );
    $bookyearfield = array(
                 'key' => 'book_year',
                 'value' => pods_var( 'search' ),
                 'compare' => 'LIKE'
              );

    After this, I used if, else, and isset in an attempt to get the checkbox value and pass it to my $params. If the checkbox is checked, it will search for the field. If not, then it will do nothing.

    if (isset($_GET['bookauthor']))
    	{ $searchbookauthor = $bookauthorfield; }
    else
        { $searchbookauthor = NULL; };
    
    if (isset($_GET['bookyear']))
    	{ $searchbookyear = $bookyearfield; }
    else
        { $searchbookyear = NULL; };

    Then I changed my $params into

    $params = array(
        'orderby' => 'book_year DESC',
        'limit' => 5,
        'search' => false,
        'where' => array(
             'relation' => 'OR',
              $searchbookauthor,
              $searchbookyear
    	)
    );

    But sadly, that didn’t work nor the dozen attempts I made during the past few days. =(
    How do I connect these checkboxes to echo $pod->filters() ?

    https://www.ads-software.com/plugins/pods/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter senyoraangelica

    (@senyoraangelica)

    Okay, okay, I admit it was naive and dumb of me to assume that my checkboxes would somehow magically merge with the form from filters. lol

    How do I add my checkboxes inside echo $pod->filters() ? Is there another way I could echo filters so that I can manually put my checkboxes in?—so that my checkbox values would also get submitted via the search submit button? I would extremely appreciate your advice. =D

    Thread Starter senyoraangelica

    (@senyoraangelica)

    Nevermind. I think I figured it out. ??

    Thread Starter senyoraangelica

    (@senyoraangelica)

    Just to clarify, is echo $pod->filters() exactly the same as the following code?

    <form action="" method="get" class="pods-form-filters pods-form-filters-books" action>
        <input type="hidden" name="type" value="books">
    	<input type="text" class="pods-form-filters-search" name="search" value="">
        <input type="submit" class="pods-form-filters-submit" value="Search">
    </form>

    I inserted my checkboxes inside and everything seems to be working fine now but I’d rather not miss anything important that may cause problems in the future.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to pass checkbox value to echo $pod->filters()’ is closed to new replies.