Forum Moderators: coopster
For your standard checkbox, the source code would be:
<input type="checkbox" name="product" value="pdt"> Mobile Computers <br />
'name="product"' spans throughout all the checkboxes,
while the 'value=' varies depending on the name of the checkbox they click.
To send the email, the person before me set up this page to submit to another page that goes ahead and generates the email. The lines of code for the checkboxes look something like this:
$message .= '<br />PDTs: ';
$message .= $pdt;
Please let me know what I should go about doing. I'm rather new to PHP and this is for a work situation, so any help would be appreciated. Thanks!
Funny you should ask ... I've just finished coding a similar thingy.
My habit for coding checkboxes is to use a slightly different name pattern than you show in your post. I've found it makes it really easy to handle checkboxes.
Instead of
name="product", I would use name="product[]" to create a single form element which is an array. Then, on the processing page, I can simply do (using your code snippet): foreach($_POST["product"] as $key => $pdt) { $message .= '<br />PDTs: '. $pdt; } (The
$key in this loop will always be product[n] where n is the array element's position.) Any checkboxes not checked will not be included (as usual). Any checked checkboxes will receive their own line in
$message. Hope that's helpful.