bwakad Posted April 29, 2014 Share Posted April 29, 2014 On my search form I wanted to make the selected value return back as what was selected to search. But I'm really having trouble retrieving this value. I'm not sure what I do wrong... My search_form.php (included in head.inc) code is this: <form id="search_form" method="GET" action="<?php echo $config->urls->root?>search/"> <label for='search_provincie'>Provincie <select id='search_provincie' name='provincie'> <option value=''>Any</option> // generate the provincie options, checking the whitelist to see if any are already selected foreach($pages->get("/provincie/")->children() as $provincie) { $selected = $provincie->name == $input->get($provincie) ? " selected='selected' " : ''; echo "<option$selected value='{$provincie->name}'>{$provincie->title}</option>"; } </select> </label> <button type="submit" class="button postfix" id="search_submit">Search</button> </form> and my search.php file is this: $selector = ''; if($input->get->provincie) { // Get the criteria and sanitize them $provincie = $pages->get("/provincie/" . $sanitizer->pageName($input->get->provincie)); if($provincie->id) { $selector .= ", provincie=$provincie"; $input->whitelist('provincie', $provincie->name); } } When I use the following code I retrieve it's chosen value: $value = $input->get('provincie'); echo $value; EDIT --------------------- changed my search form to this dropdown code so now it works as expected: <option value=''>Any</option><?php foreach($pages->get("/provincie/")->children() as $provincie) { // when my page parent is 'provincie' I know the children are select values, // then use (current) $page->name as $provincie->name. if ($page->parent->get("name") === "provincie") { $selected = $provincie->name == $page->name ? " selected='selected' " : ''; // when page parent is not 'provincie' I am on the search page, then use $provincie->name. } else { $selected = $provincie->name == $input->get('provincie') ? " selected='selected' " : ''; } echo "<option$selected value='{$provincie->name}'>{$provincie->title} </option>"; } ?> Next thing is, I have only 1 template file to browse all parents and all children under it, and 1 search file. But since my 1 template file is very dynamic I am thinking of making my search form redirect to this template as well. Unfortunatly, that is not yet working because I get a 'page does not exist' . On a separate search file it is working though. 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