I need to send send check box information to php using form, but using below code I am getting undefined index error if check box is not checked.
<form name="frmUser" method="post" action="" align="center" autocomplete="on">
<input id=user_id type="text" placeholder="Username" name="username" autocomplete="on">
<input id=pwd_id type="password" placeholder="Password" name="password" autocomplete="on">
<div class="form-check" style="margin-top:5px;">
<input type="checkbox" class="form-check-input" id="autologin_id" value="value2" name="autologin_checkbox">
<label style="color:#49495f;" class="form-check-label" for="autologin_id">AutoLogin</label>
</div>
<div class="form-check" style="margin-top:5px;">
<input type="checkbox" class="form-check-input" id="data_id" value="value3" name="data_checkbox">
<label style="color:#49495f;" class="form-check-label" for="data_id">Data</label>
</div>
<input type="submit" name="submit" value="Login" value="Login">
</form>
if (isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])) {
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$autologin_checkbox = $_POST['autologin_checkbox'];
$data_checkbox = $_POST['data_checkbox'];
}
But when I run the code without check the chckobx getting follwing error on php.
undefined index autologin_checkbox
undefined index data_checkbox