Jump to content

PHP question


alec
 Share

Recommended Posts

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

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');
}
 
  • Like 2
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...