Jump to content

search form is not working


mrkhan
 Share

Recommended Posts

Hello, 

i am trying to built one job search form but its not working, bellow is my code

<form method="get" action="<?=$config->urls->root;?>search/">
<input type="text"  placeholder="Keyword Search" name="keyword" id="keyword">

<select name="job_sector" id="job_sector">
<option>All Sectors</option>
<option>Human Resources</option>
<option>Consulting</option>
</select>
<select name="job_level" id="job_level">
<option>All Jobs Level</option>
<option>Executive</option>
<option>Manager</option>
</select>
<select name="job_location" id="job_location" >
<option>All Locations </option>
<option>city1</option>
<option>city2</option>
</select>
<input type="submit" class="btn btn-primary btn-medium" value="Search Jobs" >
</form>

<?php
$search_cat="";

// find any matching keyword
if($input->get->job_keyword) {
$search_cat="job_keyword~=".$input->get->job_keyword;
}

if($input->get->job_sector) {
$search_cat=$search_cat.",job_sector=".$input->get->job_sector;
}

if($input->get->job_level) {
$search_cat=$search_cat.",job_level=".$input->get->job_level;
}

if($input->get->job_location) {
$search_cat=$search_cat.",job_location=".$input->get->job_location;
}

$jobs=$pages->find("template=job,$search_cat");
foreach($jobs as $job)
{ 
?> 

but this code is not working.

i want to find all pages with template job and any field select on form.

Thanks

Link to comment
Share on other sites

Have a look at how this is done in the Skyscraper's profile. Download the profile and look at the code, especially the search.php file.

https://processwire.com/talk/topic/2491-skyscrapers-profile/

http://demo.processwire.com/

http://modules.processwire.com/modules/skyscrapers-profile/

You also need to sanitize (and maybe whitelist) all inputs (even if they are coming from HTML select options).

  • Like 1
Link to comment
Share on other sites

Hello kongondo,

thanks for your reply and i have download the profile but its different than i am looking for.

i have job pages with template name job. i want to search from these pages.

can you give me example of combining two select box in 

$jobs=$pages->find("template=job,$search_cat");

for example i have one select box name "select A" and other is "select B", how can i combine these two in above search if value is selected.

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...