重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

電子書籍の厳選無料作品が豊富!

PHPで
<p>曜日</p>
<p>
<input type="checkbox" name="youbi[]" value="1" <?php if(strstr($result[4],'1')) echo"checked"; ?>>月
<input type="checkbox" name="youbi[]" value="2" <?php if(strstr($result[4], '2')) echo"checked"; ?>>火
<input type="checkbox" name="youbi[]" value="3" <?php if(strstr($result[4],'3')) echo"checked"; ?>>水
<input type="checkbox" name="youbi[]" value="4" <?php if(strstr($result[4],'4')) echo"checked"; ?>>木
<input type="checkbox" name="youbi[]" value="5" <?php if(strstr($result[4],'5')) echo"checked"; ?>>金
<input type="checkbox" name="youbi[]" value="6" <?php if(strstr($result[4],'6')) echo"checked"; ?>>土
<input type="checkbox" name="youbi[]" value="0" <?php if(strstr($result[4],'0')) echo"checked"; ?>>日
</p>
<p>時間</p>
<p>
<input type="submit" value="設定" />
とやると日曜日を選択してsubmitするとチェックが外れます。なぜでしょうか?

A 回答 (1件)

<?PHP


$youbi=filter_input(INPUT_POST,"youbi",FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
$checkbox["youbi"]=array_map(function($x){return "";},range(0,6));
if(!is_null($youbi)){
foreach($youbi as $val){
$checkbox["youbi"][$val]=" checked";
}
}
var_dump($youbi);
?>
<form method="post">
<label><input type="checkbox" name="youbi[]" value="1"<?=$checkbox["youbi"][1]?>>月</label>
<label><input type="checkbox" name="youbi[]" value="2"<?=$checkbox["youbi"][2]?>>火</label>
<label><input type="checkbox" name="youbi[]" value="3"<?=$checkbox["youbi"][3]?>>水</label>
<label><input type="checkbox" name="youbi[]" value="4"<?=$checkbox["youbi"][4]?>>木</label>
<label><input type="checkbox" name="youbi[]" value="5"<?=$checkbox["youbi"][5]?>>金</label>
<label><input type="checkbox" name="youbi[]" value="6"<?=$checkbox["youbi"][6]?>>土</label>
<label><input type="checkbox" name="youbi[]" value="0"<?=$checkbox["youbi"][0]?>>日</label>
<hr>
<input type="submit" value="設定">
<form>
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!