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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.