T.Doe T.Doe - 3 months ago 15
HTML Question

How to add an if statement to my search form - Wordpress/Woocommerce

Using the inbuilt Wordpress 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 so can anybody please help me with what I've done wrong? Thank you in advance!

Answer
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; ?>