I have an array of checkbox and after POST the check mark disappears. I've tried different solutions but doesn't seem to work. I'm not sure if it is due to the complicated values of the checkbox. The values have special characters, I'm not sure if it matters. Please see my code below.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
if (isset($_POST["check"]))
$brand = $_POST["check"];
else
$check="";
?>
<input type="checkbox" name="check[]" value="request LIKE '%<text1>%'" <?php if(isset($_POST["check"][0]))
{ if($_POST["check"][0]=="request LIKE '%<text1>%'"){ echo 'checked="checked"';} } ?>><label>Option 1</label>
<input type="checkbox" name="check[]" value="request LIKE '%<text2>%'" <?php if(isset($_POST["check"][0]))
{ if($_POST["check"][0]=="request LIKE '%<text2>%'"){ echo 'checked="checked"';} } ?>><label>Option 2</label>
</form>
This doesn't work as well:
<input type="checkbox" name="check[]" value="request LIKE '%<text1>%'"<?=(in_array("request LIKE '%<text1>%'", $check) ? ' checked="checked"' : '') ?> />
Aucun commentaire:
Enregistrer un commentaire