2014-04-10 110 views
0

我想弄清楚为什么这段代码不会传递提交时隐藏输入字段的值。传递输入隐藏值与JQuery

该代码是从WordPress模板页面中提取出来的,我已将其从所有特性WP标签中删除,以便将其粘贴到此处。字段ID是“截止”。

<?php 

$cutoffdate = $_POST['cutoff']; 
$school = empty($_COOKIE['school']) ? null : $_COOKIE['school']; 
$department = empty($_COOKIE['department']) ? null : $_COOKIE['department']; 

if (! empty($_POST['school'])) { 
setcookie('school', $_POST['school'], time() + 3600 * 24 * 30, '/'); 
setcookie('department', @$_POST['department'], time() + 3600 * 24 * 30, '/'); 

header('Location: '. $_SERVER['REQUEST_URI']); 
exit; 
} 


if (! $school) { 
    /*some code here */ } 

elseif ($cutoffdate == "1") { 
?> 
<div> 
<form> 
<select id="school" name="school"> 
<option value="97" >Art Center College of Design</option> 
<option value="96" >Biola University</option> 
<option value="4" selected='selected'>California State University, Bakersfield</option> 
<option value="22" >California State University, Pomona</option> 
<option value="27" >California State University, San Marcos</option> 
<option value="31" >Occidental College</option> 
<option value="32" >Seminole State College of Florida</option> 
<option value="89" >University of California, Davis</option> 
<option value="90" >University of California, San Diego</option> 
<option value="43" >University of Central Florida</option> 
<option value="48" >University of Phoenix</option> 
<option value="91" >Woodbury University</option> 
</select> 

     <input type="hidden" id="cutoff" name="cutoff" value="" /> 
     <br> 
    </form> 
    <?php endif; ?> 



    </div> 
    <script type="text/javascript"> 

jQuery( 

function ($) { 

    $('#school').change(function (e) { 

    var unihashtable = new Array(); 
     var unicutofftable = new Array(); 

     unihashtable[4] = 'California State University, Bakersfield'; 
     unihashtable[22] = 'California State University, Pomona'; 
     unihashtable[27] = 'California State University, San Marcos'; 
     unihashtable[31] = 'Occidental College'; 
     unihashtable[32] = 'Seminole State College of Florida'; 
     unihashtable[43] = 'University of Central Florida'; 
     unihashtable[48] = 'University of Phoenix'; 
     unihashtable[89] = 'University of California, Davis'; 
     unihashtable[90] = 'University of California, San Diego'; 
     unihashtable[91] = 'Woodbury University'; 
     unihashtable[96] = 'Biola University'; 

     unicutofftable[4] = new Date(2014, 0, 11, 21, 0, 0); 
     unicutofftable[22] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[27] = new Date(2014, 4, 14, 21, 0, 0); 
     unicutofftable[31] = new Date(2014, 4, 16, 21, 0, 0); 
     unicutofftable[32] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[43] = new Date(2014, 3, 28, 21, 0, 0); 
     unicutofftable[48] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[89] = new Date(2014, 5, 10, 21, 0, 0); 
     unicutofftable[90] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[91] = new Date(2014, 4, 8, 21, 0, 0); 
     unicutofftable[96] = new Date(2014, 4, 21, 21, 0, 0); 


     for (var i in unihashtable) { 


      if (i == $('#school').val()) { 

       datecheck = new Date(); 
       if (datecheck > unicutofftable[i]) { 
        $("[name='cutoff']").val(1); 
        alert("Some Alert"); 
        this.form.submit(); 


        } else { this.form.submit(); } 

      } 

     } 






    } ); 


}); 
</script> 
<?php } 

else { 
?> 


<div> 
<form> 
<select id="school" name="school"> 
<option value="97" >Art Center College of Design</option> 
<option value="96" >Biola University</option> 
<option value="4" selected='selected'>California State University, Bakersfield</option> 
<option value="22" >California State University, Pomona</option> 
<option value="27" >California State University, San Marcos</option> 
<option value="31" >Occidental College</option> 
<option value="32" >Seminole State College of Florida</option> 
<option value="89" >University of California, Davis</option> 
<option value="90" >University of California, San Diego</option> 
<option value="43" >University of Central Florida</option> 
<option value="48" >University of Phoenix</option> 
<option value="91" >Woodbury University</option> 
</select> 
     <input type="hidden" id="cutoff" name="cutoff" value="" /> 
     <br> 

    </form> 
    <?php endif; ?> 




</div> 

<script type="text/javascript"> 

jQuery( 

function ($) { 

    $('#school').change(function (e) { 

    var unihashtable = new Array(); 
     var unicutofftable = new Array(); 

     unihashtable[4] = 'California State University, Bakersfield'; 
     unihashtable[22] = 'California State University, Pomona'; 
     unihashtable[27] = 'California State University, San Marcos'; 
     unihashtable[31] = 'Occidental College'; 
     unihashtable[32] = 'Seminole State College of Florida'; 
     unihashtable[43] = 'University of Central Florida'; 
     unihashtable[48] = 'University of Phoenix'; 
     unihashtable[89] = 'University of California, Davis'; 
     unihashtable[90] = 'University of California, San Diego'; 
     unihashtable[91] = 'Woodbury University'; 
     unihashtable[96] = 'Biola University'; 

     unicutofftable[4] = new Date(2014, 0, 11, 21, 0, 0); 
     unicutofftable[22] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[27] = new Date(2014, 4, 14, 21, 0, 0); 
     unicutofftable[31] = new Date(2014, 4, 16, 21, 0, 0); 
     unicutofftable[32] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[43] = new Date(2014, 3, 28, 21, 0, 0); 
     unicutofftable[48] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[89] = new Date(2014, 5, 10, 21, 0, 0); 
     unicutofftable[90] = new Date(2014, 5, 11, 21, 0, 0); 
     unicutofftable[91] = new Date(2014, 4, 8, 21, 0, 0); 
     unicutofftable[96] = new Date(2014, 4, 21, 21, 0, 0); 


     for (var i in unihashtable) { 


      if (i == $('#school').val()) { 

       datecheck = new Date(); 
       if (datecheck > unicutofftable[i]) { 
        $("[name='cutoff']").val(1); 
        alert("Some Alert"); 

        this.form.submit(); 


        } else { this.form.submit(); } 

      } 

     } 






    } ); 


}); 
</script> 

<?php 
}; 

我可能失去了一些东西基本还是很明显的,但我只是不明白为什么这不工作...

回答

0

的权利,我想通了,什么是错的:

if (! empty($_POST['school'])) { 
setcookie('school', $_POST['school'], time() + 3600 * 24 * 30, '/'); 
setcookie('department', @$_POST['department'], time() + 3600 * 24 * 30, '/'); 

header('Location: '. $_SERVER['REQUEST_URI']); 
exit; 
} 

这里的头文件函数重定向并杀死$ _POST值。虽然我不能100%说它是标题本身,而不是退出这一切都搞砸了。我会爱如果谁知道更多可以解释也许...