Jump to content

Checkboxes and Emails


dmschenk

Recommended Posts

I am trying to build a form that changes the email addresses depending on the checkboxes that are checked. 

I am at a total loss getting multiple checkboxes to populate the email variable.  I'm not sure if the checkboxes need differing names or the same name. I get an error that says checkboxes with the same name needs to be in brackets[].  With different names I can't get anything to work.  :-[

Can someone please point me in the right direction?

 

Thanks

Dave

Link to comment
https://forums.phpfreaks.com/topic/76514-checkboxes-and-emails/
Share on other sites

I'm not sure what you're needing to do, but here is the basic principle to passing multiple values through one variable:

<?php
if (isset($_POST['selections']))
{
  $out = implode(', ' $_POST['selections']); // Treat it as an array
  echo "You have chosen: $out";
}

echo "<form name='my_form' action='' method='post'>\n";
for ($i = 1; $i <= 10; $i++)
{
  echo "<input type='checkbox' name='selections[]' value='$i' /> $i<br />\n";
}
echo "<input type='submit' name='submit' value='Choose!' />
echo "</form>\n";
?>

 

Hope this helps.

Link to comment
https://forums.phpfreaks.com/topic/76514-checkboxes-and-emails/#findComment-387546
Share on other sites

Thanks for the quick reply. I'll give this a try tonight to see if I can get it to work.

 

The form I'm trying to build is more or less a signup sheet to request info from a list of departments and depending on the box(es) you check it sends an email to that department to notify them you are interested in something. There are 30+ departments in the list and while I'm not sure this is the best or recommended method it was the best I could come up with.

 

Thanks

Dave

Link to comment
https://forums.phpfreaks.com/topic/76514-checkboxes-and-emails/#findComment-387595
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.