alec Posted March 4, 2014 Share Posted March 4, 2014 Hello comunity. I have little problem with search form and templates. This is more like php question so I will appreciate for your help. I have "home" template, where I want to put search form and display it on main file. Form is in html div. Because if I put form directly in main file, then it would be show on every page, but i only want to show search form on home page. Now, question is, how can I put form in function, or php variable and later include in main file. I have try with "if" statement on main file, but it doesn't work. Here is form: <form id='search-form' action='<?php echo $config->urls->root?>search/' method='get' class='hide-for-small'> <div class="row collapse"> <div class="small-9 columns"> <input type="text" name="q" value="<?php echo $sanitizer->entities($input->whitelist('q')); ?>" placeholder="" /> </div> <div class="small-3 columns"> <button type='submit' class="button prefix">Search</button> </div> </div> </form> </div> Link to comment Share on other sites More sharing options...
diogo Posted March 4, 2014 Share Posted March 4, 2014 You don't have to put it in a function, you can as well just put all this inside a if statement <?php if (condition) : ?> <form id='search-form' action='<?php echo $config->urls->root?>search/' method='get' class='hide-for-small'> <div class="row collapse"> <div class="small-9 columns"> <input type="text" name="q" value="<?php echo $sanitizer->entities($input->whitelist('q')); ?>" placeholder="" /> </div> <div class="small-3 columns"> <button type='submit' class="button prefix">Search</button> </div> </div> </form> <?php endif; ?> or, if this complicates the code on that template too much, you can have have it exactly as it is in a file, and include it from inside the condition. if (condition) { include('form.inc'); } 2 Link to comment Share on other sites More sharing options...
alec Posted March 4, 2014 Author Share Posted March 4, 2014 Yes, i found "include" like possible answer. Thank you, @diogo Link to comment Share on other sites More sharing options...
SteveB Posted March 4, 2014 Share Posted March 4, 2014 Just FYI, include really isn't a function This does work, nothing wrong with it: include('form.inc'); But this is at least as good and 2 characters less: include 'form.inc'; 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