0

So I have a page where users can edit their profile. There users first get data fetched from my database so for example one of the checkboxes is checked. Then I want the users to be able to update their checkboxes but for some reason the "post" method doesn't pass the right data. My view:

<form method="post" action="<?php echo $this->config->base_url(); ?>index.php/profile/update/<?php echo $user['patient_id']; ?>">
    <div>
<?php 
    if($user['sport_ban']){
        $checked = "checked";
    }else{
        $checked = "";  
    }
    echo "Sport ban: "."<input type='checkbox' name='sport_ban'
                        value='".$user['sport_ban']."'".$checked.">";
 ?>
    </div>
    <input type="submit" value="Aanpassingen opslaan" name="submit">
</form>

my controller:

$gele_kaart = $this->input->post('gele_kaart');
$sport_ban = $this->input->post('sport_ban'); 
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • So what data DOES the post pass – RiggsFolly Mar 24 '20 at 16:44
  • You might like to put a space between the end of the `value` tag and the checked like `value='".$user['sport_ban']."' ".$checked.">";` – RiggsFolly Mar 24 '20 at 16:45
  • Or even use the automatic variable expansion in double quotes literals and do `value='$user[sport_ban]' $checked>";` – RiggsFolly Mar 24 '20 at 16:46
  • Thank you for your reaction, i don't exactly know what the post passes. It passes if i let the checkbox as it is when it is one. – wannesvdp Mar 24 '20 at 16:53
  • I was thinking it might have something to do with the fact that the checkbox has an attribute $checked on loading? But i don't see any other way to actually check the checkbox – wannesvdp Mar 24 '20 at 17:12

0 Answers0