select option value always get null

Question

I try to make custom theme option, a switch select option can change $bannerchange value. but i cannot add/update value of $bannerchange, select option inside a form. $companysnippet variable working fine but come to the select option result get null value. what i did wrong.

<?php
if(isset($_POST['wphw_submit'])){
        wphw_opt();
}
function wphw_opt(){
    $companysnippet = $_POST['companysnippet'];
    $bannerchange = $_POST['bannerchange'];
    if( get_option('companysnippet') != trim($companysnippet)) {
        $chk = update_option( 'companysnippet', trim($companysnippet));
    }
    if( get_option('bannerchange') != $bannerchange) {
        $chk = update_option( 'bannerchange', $bannerchange);
    }
}?>
  <form method="post" action="">         
        <textarea type="text" name="companysnippet"><?php echo get_option('companysnippet');?></textarea>
        <select name="bannerchange">
            <option value="page1"<?php if ($bannerchange == "page1") { echo " selected"; } ?>>Custom Departure</option>
            <option value="page2"<?php if ($bannerchange  == "page2") { echo " selected"; } ?>>Fixed Departure</option>
        </select>
        <input type="submit" name="wphw_submit" value="Save changes" class="button-primary" />
  </form><?php 
switch ($bannerchange) { 
    case 'page2': 
        break;
    case 'page1':
        break; 
}  

$bannerchange get always undefined. I can debug this problem with straight way? any help greatly appreciated.

0
Noufal Binu 3 months 0 Answers 9 views 0

Leave an answer