0

I want to submit the form with empty checkbox but I want the value "no" if the checkbox is not checked.

if($Domain_Check=="yes")
{
    echo '<div class="col-md-3">
            <div class="form-group" style="padding-top:20px;">
                Domain_Check   <input type="checkbox" name="Domain_Check1" value="yes" checked>
            </div>
         </div>';
}
else {
    echo '<div class="col-md-3">
             <div class="form-group" style="padding-top:20px;">
                Domain_Check   <input type="checkbox" name="Domain_Check1" value="yes">
             </div>
          </div>';
} 
Wand Maker
  • 18,476
  • 8
  • 53
  • 87
Haris M
  • 99
  • 1
  • 10

1 Answers1

0

Use a hidden input before the checkbox to set a default value with the same name:

<input type="hidden" name="Domain_Check1" value="no">
<input type="checkbox" name="Domain_Check1" value="yes">

The hidden input will be overridden if the checkbox is checked.

spenibus
  • 4,339
  • 11
  • 26
  • 35