Key Posted August 1, 2014 Share Posted August 1, 2014 First of All, Thanks to PW Team for bringing us such a great CMS. I downloaded copy early this year but started work on it yesterday. I created few template files for search and results but one of the custom field is not displaying any result. Text field name is "roll_no", which contains only numbers and this is the code for search template. Student name and Father name fields are showing results. <?php /** * Search template * */ $out = ''; if($q = $sanitizer->selectorValue($input->get->q)) { $input->whitelist('q', $q); $matches = $pages->find("title|roll_no|student_name|father_name~=$q, limit=50"); $count = count($matches); if($count) { $out .= "<h2>Found $count results matching your query:</h2>" . "<table class='result'><tr><th>Student Name</th><th>Father Name</th><th>Class</th><th>Roll No</th><th>Result</th><th>Total Marks</th></tr>"; foreach($matches as $m) { $out .= "<tr><td><a href='{$m->url}'>{$m->title}</a></td><td>{$m->father_name}</td><td>{$m->class}</td><td>{$m->roll_no}</td><td>{$m->result}</td><td>{$m->numbers}</td></tr>"; } $out .= "</table>"; } else { $out .= "<h2>Sorry, no results were found.</h2>"; } } else { $out .= "<h2>Please enter a search term in the search box (upper right corner)</h2>"; } include("./head.inc"); echo $out; include("./foot.inc"); My another question is about Search input field.. I setup a custom select field with Fieldtype: Select module. Feild name is "class" with 4 options (7th, 8th, 9th, 10th).. I also want to display these select options beside search input field. So user enter student name or roll no and then choose class for results. This is code for exam page template with search input field. <?php include("./head.inc"); ?> <form id='search_form' action='<?php echo $config->urls->root?>result-search/' method='get' class="search-form"> <input type='text' name='q' id='search_query' value='<?php echo htmlentities($input->whitelist('q'), ENT_QUOTES, 'UTF-8'); ?>' class="search-text-box" /> <input type='submit' id='search_submit' class="search-submit-button" /> </form> <?php include("./foot.inc"); ?> Any help would be really appriciated. Link to comment Share on other sites More sharing options...
adrian Posted August 5, 2014 Share Posted August 5, 2014 Hi Key and welcome to the forums. Have you tried *= or %= in your selector? http://processwire.com/api/selectors/ As for your second question. You'd really be better off using a page field instead of the select fieldtype for this type of usage. It might seem tedious to set up at first, but gives you so much more flexibility. You might find this module useful for setting it up: http://modules.processwire.com/modules/process-page-field-select-creator/ Hope that helps. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now