Reputation: 2035
Using the inbuilt WordPress search form:
<form role="search" method="get" class="search-form">
<?php
if ( function_exists( 'woocommerce_product_search' ) ) {
echo woocommerce_product_search( array( 'limit' => 40 ) );
}
?>
<div class="col-lg-4 col-lg-offset-4">
<div class="input-group">
<input type='textbox' maxlength="8" id="item-search" name="s" class="form-control form-inline" value="<?php the_search_query();?>" placeholder="Enter your postcode e.g. SW1Y 4LG"/>
<span class="input-group-btn">
<button class="item-search-btn">search</button>
</span>
</div>
</div>
</form>
I have called it to appear on my home page (index.php):
<?php get_search_form(); ?>
I want to add an if statement to display:
<div id="postcode-no" class="col-lg-4 col-lg-offset-4">
Unfortunately this is incorrect.
</div>
So to my index.php file I have added:
<?php if (input-text=='SW12') { ?>
<div id="postcode-no" class="col-lg-4 col-lg-offset-4">
Unfortunately this is incorrect.
</div>
<?php } else if (input-text=='SW15'){ ?>
<div id="postcode-no2" class="col-lg-4 col-lg-offset-4">
Correct.
</div>
<?php } ?>
But it's not working. I'm fairly new to PHP. What have I done wrong?
Upvotes: 3
Views: 125
Reputation: 150
Chaneg the var input-text to $input_text than try
<?php if ($input_text=='SW12'): ?>
<div id="postcode-no" class="col-lg-4 col-lg-offset-4">
Unfortunately this is incorrect.
</div>
<?php elseif ($input_text=='SW15'): ?>
<div id="postcode-no2" class="col-lg-4 col-lg-offset-4">
Correct.
</div>
<?php else: ?>
<div id="postcode-no2" class="col-lg-4 col-lg-offset-4">
Some Else.
</div>
<?php endif; ?>
Upvotes: 1