我有作为数组传递给 URL 的复选框,在页面重新加载时我应该将它们取回,以便记住检查的内容。
这是我的javascript,有问题的数组是'entry_reason':
<script language="JavaScript">
<!--
function reload(nname, surname, birth_date, birth_country, birth_place, postal_code, address, residence, oib, license_number, license_iplace, passport_number, passport_iplace, entry_reason, myself, myselfeng)
{
// Setting the variable with the value of selected country's ID
var nname=document.getElementById('nname').value;
var surname=document.getElementById('surname').value;
var birth_date=document.getElementById('birth_date').value;
var c=document.getElementById('birth_country').value;
var city=document.getElementById('birth_place').value;
var postal_code=document.getElementById('postal_code').value;
var address=document.getElementById('address').value;
var residence=document.getElementById('residence').value;
var oib=document.getElementById('oib').value;
var license_number=document.getElementById('license_number').value;
var license_iplace=document.getElementById('license_iplace').value;
var passport_number=document.getElementById('passport_number').value;
var passport_iplace=document.getElementById('passport_iplace').value;
var entry_reason=[document.getElementById('entry_reason1').value, document.getElementById('entry_reason2').value, document.getElementById('entry_reason3').value, document.getElementById('entry_reason4').value, document.getElementById('entry_reason5').value, document.getElementById('entry_reason6').value, document.getElementById('entry_reason7').value];
var myself=document.getElementById('myself').value;
var myselfeng=document.getElementById('myselfeng').value;
// Sending the country id in the query string to retrieve the city list
self.location='blacklistprivateregister.php?nname=' + nname + '&surname=' + surname + '&birth_date=' + birth_date + '&birth_country=' + c + '&birth_place=' + city + '&postal_code=' + postal_code + '&address=' + address + '&residence=' + residence + '&oib=' + oib + '&license_number=' + license_number + '&license_iplace=' + license_iplace + '&passport_number=' + passport_number + '&passport_iplace=' + passport_iplace + '&entry_reason[]=' + entry_reason + '&myself=' + myself + '&myselfeng=' + myselfeng;
}
-->
</script>
我得到的 URL 看起来像这样:
http://xxxxxxxx.php?nname=ivo&surname=&birth_date=2012-11-08&birth_country=Algeria&birth_place=Benguela&postal_code=10000&address=%C4%8Ci%C4%8Dkovina%20222&residence=Zagorne&oib=1231231232131&license_number=21312323213&license_iplace=Zagreb&passport_number=000493243244&passport_iplace=Vara%C5%BEdin&entry_reason[]=1,2,3,4,5,6,7&myself=aasddsad&myselfeng=asdadasd
带有我的输入复选框的地方是这样的:
<legend><?php echo REASONFORENTRY_R; ?></legend>
<?php
$e=array();
if(isset($_POST['entry_reason'])){ $e=$_POST['entry_reason'];}
if($_GET['entry_reason']) {$e=$_GET['entry_reason'];}
?>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason1" class="check" value="1" <?php if(in_array('1', $e)) echo 'checked="checked" '; ?>/><?php echo ER1_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason2" class="check" value="2" <?php if(in_array('2', $e)) echo 'checked="checked" '; ?>/><?php echo ER2_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason3" class="check" value="3" <?php if(in_array('3', $e)) echo 'checked="checked" '; ?>/><?php echo ER3_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason4" class="check" value="4" <?php if(in_array('4', $e)) echo 'checked="checked" '; ?>/><?php echo ER4_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason5" class="check" value="5" <?php if(in_array('5', $e)) echo 'checked="checked" '; ?>/><?php echo ER5_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason6" class="check" value="6" <?php if(in_array('6', $e)) echo 'checked="checked" '; ?>/><?php echo ER6_R; ?></p>
<p><input type="checkbox" name="entry_reason[]" id="entry_reason7" class="check" value="7" <?php if(in_array('7', $e)) echo 'checked="checked" '; ?>/><?php echo ER7_R; ?></p>
我在网站上有 3 个操作,其中 2 个我希望记住复选框:1)在 javascript 函数重新加载时页面重新加载 2)在提交时页面重新加载错误 - 这个现在可以与 $_POST 一起使用
我认为对于第一次重新加载,我应该将所有变量项从 URL 获取到 $_GET 并将它们传递给 $e 变量,但它似乎不起作用。
感谢所有帮助!