Search page question

0

I have a search page where I'm currently using this code to display a search filter. This shows a location dropdown, text field and search button. This appears at the top of a template I have called "member_list" which lists all of the members of the site. The thing is I don't want any of those members to show when I launch this search page. I'd like it blank until I perform a search. Is there any way to do this?

<?php
// sanitize the search param from the URL
if (isset($_GET["search"])) {
    $result = addslashes($_GET["search"]); 
}
// invoke Pods with the chosen pod as the param
$Record = new Pod('member');

// the param 'member_type' is a pick field that is part of the members Pod, you can add multiple picks as a comma-delimited list
// the param 'Search' just changes what the submit button says

echo $Record->getFilters('location','search');

// 'name ASC' returns results in Ascending order -- alpha by name
// 10 is return 10 results on a page
// %$result% is the user input from the textfield (see the if statement above)
$Record->findRecords('t.name ASC', 10, "(t.name LIKE '%$result%')");

// display pagination for the results, if needed
echo $Record->getPagination(); 

// if($Record->getTotalRows()<1){echo 'No records found. Please try your search again.';}
// uncomment the line below to echo the sql statement generated by findRecords() -- invaluable for troubleshooting 
// echo $Record->sql;

// obviously, a template named member_list needs to exist.
echo $Record->showTemplate('member_list');
?>

asked May 14 '10 at 10:58

daretothink

11

add comment
enter at least 15 characters

15 Answers

1

A little PHP goes a long way.

$result = pods_url_variable('search', 'get');

if (!empty($result)) {
    // Add all your Pods code
}

answered May 24 '10 at 2:27

logikal16

249

edited May 24 '10 at 2:32

add comment
enter at least 15 characters
0

Anyone?

I also have another problem related to this form. When there are no results it simply removes the search filters and field so you have to use the back button on your browser in order to perform a new search?

answered May 17 '10 at 11:20

daretothink

11

add comment
enter at least 15 characters
0

Can anybody help with this?

The main problem is using the code I have listed above it simply shows all of the people from my "member_list". Now this is obvious that this will happen since it's using a template that shows all of those members.

But, I only want the search functions to be visible on page entry and not all members.

answered May 24 '10 at 1:05

daretothink

11

add comment
enter at least 15 characters
0

Please forgive me here but where do I put that code? I've attempted to integrate the code you've given above with the code in my first post but all that I seem to get, when moving things around a bit, is the search filters but when I perform a search nothing appears. I'm presuming I'm putting the code in the wrong place.

answered May 24 '10 at 5:13

daretothink

11

add comment
enter at least 15 characters
0

Try this:

<?php $result = pods_url_variable('search', 'get');

$Record = new Pod('member');

echo $Record->getFilters('location','search');

if (!empty($result)) {

$result = addslashes($result); 

$Record->findRecords('t.name ASC', 10, "(t.name LIKE '%$result%')");

echo $Record->getPagination(); 

echo $Record->showTemplate('imember_list');

} ?>

answered May 25 '10 at 8:08

jackson

33

edited May 25 '10 at 8:14

add comment
enter at least 15 characters
0

I cannot get this new editor to display code properly! Beware of the &quot; above. Sorry.

answered May 25 '10 at 8:16

jackson

33

add comment
enter at least 15 characters
0

Thanks for your help with this - much appreciated. I added the following code and whilst it removes the initial member list that appears on the page as you load the search filters, when you then do a search it just doesn't display anything below those filters?

<?php $result = pods_url_variable('search', 'get');

$Record = new Pod('member');

echo $Record->getFilters('location','search');

if (!empty($result)) {

$result = addslashes($result); 

$Record->findRecords('t.name ASC', 10, "(t.name LIKE '%$result%') AND t.live = 1");

echo $Record->getPagination(); 

echo $Record->showTemplate('member_list');
} 
?>

answered May 25 '10 at 9:35

daretothink

11

edited May 25 '10 at 2:35

add comment
enter at least 15 characters
0

Any ideas?

answered May 25 '10 at 5:56

daretothink

11

add comment
enter at least 15 characters
0

I've attempted to move around the code above but still all I get is either:

  1. Just the search filters and then when I perform a search nothing displays below
  2. Nothing on the page at all

Any further help would be greatly appreciated - this is almost the final piece of the puzzle!

answered May 26 '10 at 4:31

daretothink

11

add comment
enter at least 15 characters
0

Do you have a link you can share?

You should try adding some simple debugging messages to your code, ie:

if (!empty($result)) {
    echo 'not empty';

answered May 26 '10 at 7:24

jackson

33

add comment
enter at least 15 characters
0

I think the problem is with the template that is being used to display the results. I'm using a template called "member_list" which is laid out as follows:

<h2><a href="{@detail_url}">{@name}</a></h2>
<p><b>Profile:</b> {@profile} <a href="{@detail_url}">More</a></p>

The thing is if I were to just display this template on it's own then it will list all members I have on my site therefore I'm presuming because this is being used as the display for the search results page then on page load it's showing every member right away even though I'm yet to perform a search, which is when I want to display members.

answered May 26 '10 at 9:55

daretothink

11

add comment
enter at least 15 characters
0

I'm sorry to hassle once more but can anybody else help with this. I can't seem to get the "if" statement to function correctly as per my post above.

answered May 27 '10 at 4:18

daretothink

11

add comment
enter at least 15 characters
0

Hi. I've been racking my brains and consequently losing my mind attempting to get this to work and I can't!

I think the main problem with the code that I'm using is that when you initially enter the Search page the "member_list" template is loading right away whereas I really only need that to load when a search has been performed. So I only need the search filters to be visible on the Search page on initial load.

Just to recap the code I'm using:

I'm bring the template in using a shortcode:

[pods name="member" limit="1" template="search_template"]

The search_template is:

<?php $result = pods_url_variable('search', 'get');
$Record = new Pod('member');
echo $Record->getFilters('location','search');
if (!empty($result)) {
$result = addslashes($result); 
$Record->findRecords('t.name ASC', 10, "(t.name LIKE '%$result%') AND t.live = 1");
echo $Record->getPagination(); 
echo $Record->showTemplate('member_list'); } 
?>

The member_list template that loads is:

<h2><a href="{@detail_url}">{@name}</a></h2>
<p><b>Profile:</b> {@profile} <a href="{@detail_url}">More</a></p>

I'd really appreciate some help with this.

answered May 27 '10 at 6:05

daretothink

11

edited May 27 '10 at 6:06

add comment
enter at least 15 characters
0

FYI, addslashes isn't needed. The pods_url_variable function does its own sanitization.

<?php
$result  = pods_url_variable('search', 'get');

$Record = new Pod('member');
if (empty($result)) {
    echo $Record->getFilters('location','search');
}
else {
    $Record->findRecords('t.name ASC', 10, "(t.name LIKE '%$result%') AND t.live = 1");
    echo $Record->getPagination();
    echo $Record->showTemplate('member_list');
}
?>

answered May 28 '10 at 8:35

logikal16

249

edited May 28 '10 at 8:35

add comment
enter at least 15 characters
0

Thanks for this - I'm now in limbo with two posts that are now becoming very similar. Sorry about that.

Basically the code that you mentioned above is great in the sense that nothing displays on that page when loaded. If I then perform a text search it comes back with the results. But, and this is really important, if I simply select something from the "location" dropdown and leave the search field empty then no results are found.

Any idea how I get results to show by not having to enter text in the search field?

answered May 28 '10 at 6:20

daretothink

11

add comment
enter at least 15 characters