Storing flags in a PHP form

I know how to check the boxes on the submit form when an error occurs, but now I have a different problem. I use checkboxes with the same name where people can click 1 or more. I want it to keep only the flags that the user checked, filled in if there is a problem, for example, if they check q1 A q1B, but not q1c. I want only q1 A and Q1b to be displayed on reboot on error. Currently, all flags with the same name are marked by mistake. I tried changing the name to q1 [], but that didn't work. Could you take a look and let me know how to fix this?

Here is my code.

    <tr>
<td style="width: 124px" class="style15">Tape Recorder<?php    if(isset($problems['tape[]'])) {?><font color="red">*</font><?php } ?></td>
<td class="style9"> 
    <input name="tape[]" id="tape1" type="checkbox" value="used before," <?php   if(isset($_POST['tape[]'])) echo "checked"; ?> 
  </td>
<td class="style9"> 
    <input name="tape[]" id="tape2" type="checkbox" value="helpful in past,"        <?php   if(isset($_POST['tape[]'])) echo "checked"; ?> </td>
<td class="style9"> 
    <input name="tape[]" id="tape3" type="checkbox" value="requesting from DACC" <?php if(isset($_POST['tape[]'])) echo "checked"; ?> </td>
<td class="style9"> 
    <input name="tape[]"  id="tape4" type="checkbox" value="NA" <?php if(isset($_POST['tape[]'])) echo "checked"; ?></td>
 </tr>
  <tr>
        <td style="width: 124px">Note Taker <?php if(isset($problems['note'])) {?>      <font color="red">*</font><?php } ?></td>
<td class="style9"> 
        <input name="note" type="checkbox" value="used before," <?php if(isset($_POST['note'])) echo "checked"; ?> 
</td>
<td class="style9"> 
    <input name="note" type="checkbox" value= "been helpful in the past," <?php if(isset($_POST['note'])) echo "checked"; ?> 
<td class="style9"> 
    <input name="note" type="checkbox" value= "requesting from DACC" <?php if(isset($_POST['note'])) echo "checked"; ?> 
<td class="style9"> 
    <input name="note" type="checkbox" value="NA" <?php if(isset($_POST['note'])) echo "checked"; ?> 
</tr>
+2
source share
3 answers

:

<input name="tape[]"  id="tape[]" type="checkbox" value="NA" <?php if(isset($_POST['tape']) && is_array($_POST['tape']) && in_array('NA', $_POST['tape'])) echo 'checked="checked"'; ?> />

"NA" . - , , checked=checked.

+5

, - ,

$mailBody .= "They requested additional information on ...\n\n";
$mailBody .= $moreinfo = join("\n", $_REQUEST["moreinfo"]);
$mailBody .= "\n\n";
$mailBody .= "They also had this to say...\n\n";
$mailBody .= "$comments\n\n";

//

<input type="checkbox" name="moreinfo[selection1]" value="selection1" <?php if(isset($_POST['moreinfo']) && is_array($_POST['moreinfo']) && in_array('selection1', $_POST['moreinfo'])) echo 'checked="checked"'; ?> />  Selection 1<br>

<input type="checkbox" name="moreinfo[selection2]" value="selection2" <?php if(isset($_POST['moreinfo']) && is_array($_POST['moreinfo']) && in_array('selection2', $_POST['moreinfo'])) echo 'checked="checked"'; ?> />  Selection 2<br>

<input type="checkbox" name="moreinfo[selection3]" value="selection3" <?php if(isset($_POST['moreinfo']) && is_array($_POST['moreinfo']) && in_array('selection3', $_POST['moreinfo'])) echo 'checked="checked"'; ?> />  Selection 3<br>

, , .

0

, .

, , . !

-1

Source: https://habr.com/ru/post/1626638/


All Articles