Achmann
Achmann

Reputation: 196

Parsing HTML Checkbox checked values into php using Post

I am in a silly position where I can't figure out to get the values of the checked checkboxes.

 <form id="civilForm" method="POST" action="form.php" enctype="multipart/form-data">
<p>
 <label>
<input id="12D" name="programsRequested[]" type="checkbox" />
<span>12D</span>
</label>
</p>
<p>
<label>
<input id="xp" name="programsRequested[]" type="checkbox" />
<span>XPStorm</span>
</label>
</p>
<p>
<label>
<input id="autoTurn" name="programsRequested[]" type="checkbox" />
<span>AutoTurn</span>
</label>
</p>
<p>
<label>
<input id="hecras" name="programsRequested[]" type="checkbox" />
<span>HEC RAS</span>
</label>
</p>

Then I am using a php loop as there are a bunch more checkboxes coming.

It spins through fine, but only give me a list that says: on, on, on which correctly tells me how many I checked, however does not give me the value of the checked box.

$selectedPrograms  = 'None';
if(isset($_POST['programsRequested']) && is_array($_POST['programsRequested']) && count($_POST['programsRequested']) > 0){
    $selectedPrograms = implode(', ', $_POST['programsRequested']);
}

Is there something obvious I missing on how to get the values here?

Upvotes: 0

Views: 573

Answers (1)

stalin wesley
stalin wesley

Reputation: 165

add every input element value

<input id="12D" name="programsRequested[]" type="checkbox" value="1" />

form not closed .

submit button also missing .

<input type="submit" name="submit" >

Upvotes: 2

Related Questions