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 (process.php) where we are processing the data sended by user. php ` name=name = name=_POST['name']; // Get the value of contact field // from $_POST array contact=contact = contact=_POST['contact']; // Get the value of email field // from $_POST array email=email = email=_POST['email']; // Check if at least one skill has been checked, if // checked, then assign the array returned by // POST[′skills′]to_POST['skills'] to POST[skills]toskills variable otherwise // assign an empty array skills=(isset(skills = (isset(skills=(isset(_POST['skills'])) ? $_POST['skills'] : array(); ?>

Confirmation

Name :

Email :

Contact :

Skills : 0) { foreach ($skills as $skill) { echo $skill .' '; } } else { echo "No skill has been selected"; } ?>

`

Output: