How to Get $_POST from multiple checkboxes ? (original) (raw)
How to Get $_POST from multiple check-boxes ?
Last Updated : 31 Oct, 2019
$_POST is an array of variable names. The program given below illustrates how to write HTML structure for multiple valued checkbox and to get the values of multiple valued checkbox using $_POST in PHP.Note: The name attribute of checkboxes must be the same name and must be initialized with an array. It can be done by using [] at the end of the name attribute of the checkbox.Example:
- Code: The page (index.html) containing a form having name, email, contact and skills as fields and method post. Please note that for skills, every checkbox input has skills[] in name attribute. html `
How to Get $_POST from
multiple checkboxes?
Name :
<div> <label>Email :</label> <input type="email" name="email"> </div> <div> <label>Skills :</label> <input type="checkbox" name="skills[]" value="Java"> Java <input type="checkbox" name="skills[]" value="Php"> PHP <input type="checkbox" name="skills[]" value="Python"> Python <input type="checkbox" name="skills[]" value="JavaScript"> JavaScript </div> <div> <label>Contact :</label> <input type="number" name="contact"> </div> <div> <button type="submit">Submit</button> </div>
Confirmation
Name :
Email :
Contact :
Skills : 0) { foreach ($skills as $skill) { echo $skill .' '; } } else { echo "No skill has been selected"; } ?>
`Output: