Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php mailer form, multiple checkboxes
Old 09-08-2008, 10:42 AM php mailer form, multiple checkboxes
Junior Talker

Posts: 2
Name: Thom
Trades: 0
Hi,

Im looking for some help. Ive been tearing my hair out for the last 3hours trying to work this one out.

Ive got a html form that Im looking to pass the values to a php file to mail them to my email address.

I am very new to php, well just teaching myself by looking at other peoples code and have managed to get a piece of php code to work with all other parts of my form apart from the area that has multiple checkboxes.

Ive got a column of checkboxes with a javascript function only allowing the user to select a maximum of three.

I want the the values of the three boxes selected to be passed to the php and then emailed onto my like all of the other values.

Except all I am getting is the bottom selected checkbox, not the other two!

I will post up the part of my form and my whole php script.

I really appreciate any help / advice and peoples time and efforts

Thanks
Thom

=====HTML=====

<td width="100" valign="top">
Of the following elements of online marketing please select the three that... </td>
<td width="30" valign="top">

<h5>you feel have the greatest impact in delivering marketing objectives.</h5>

<input type="checkbox" name="Q5C1" value="1" onclick="chkcontrol(0)";> eDetailing</input><br><br>

<input type="checkbox" name="Q5C1" value="2" onclick="chkcontrol(1)";> eCME</input><br><br>

<input type="checkbox" name="Q5C1" value="3" onclick="chkcontrol(2)";> eNewsletters</input><br><br>

<input type="checkbox" name="Q5C1" value="4" onclick="chkcontrol(3)";> eMail marketing</input><br><br>

<input type="checkbox" name="Q5C1" value="5" onclick="chkcontrol(4)";> Closed Loop Marketing</input><br><br>

<input type="checkbox" name="Q5C1" value="6" onclick="chkcontrol(5)";> Online Market Research</input><br><br>

<input type="checkbox" name="Q5C1" value="7" onclick="chkcontrol(6)";> ePublic Relations</input><br><br>

<input type="checkbox" name="Q5C1" value="8" onclick="chkcontrol(7)";> Brand websites</input><br><br>

<input type="checkbox" name="Q5C1" value="9" onclick="chkcontrol(8)";> Company</input><br><br>

<input type="checkbox" name="Q5C1" value="10" onclick="chkcontrol(9)";> Disease area website</input><br><br>

<input type="checkbox" name="Q5C1" value="11" onclick="chkcontrol(10)";> eMail campaigns</input><br><br>

<input type="checkbox" name="Q5C1" value="12" onclick="chkcontrol(11)";> Online advisory boards</input><br><br>

<input type="checkbox" name="Q5C1" value="13" onclick="chkcontrol(12)";> Social Networks</input><br><br>

<input type="checkbox" name="Q5C1" value="14" onclick="chkcontrol(13)";> Blogging and Podcasting</input><br><br>

<input type="checkbox" name="Q5C1" value="15" onclick="chkcontrol(14)";> Podcasting</input><br><br>

<input type="checkbox" name="Q5C1" value="16" onclick="chkcontrol(15)";> Webcasting</input><br><br>

<input type="checkbox" name="Q5C1" value="17" onclick="chkcontrol(16)";> Online reputation monitoring/management</input><br><br>

<input type="checkbox" name="Q5C1" value="18" onclick="chkcontrol(17)";> SMS marketing</input><br><br>

<input type="checkbox" name="Q5C1" value="19" onclick="chkcontrol(18)";> Twitter</input>

</td>


=====PHP=====

<script language="php">
$email = $HTTP_POST_VARS[email];
$mailto = "thom.rimmer@hotmail.co.uk";
$mailsubj = "Form submission";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>
rimmet is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-08-2008, 02:15 PM Re: php mailer form, multiple checkboxes
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
If I am thinking right (which I may not be)... what you need to do is change your inputs to look like this:

HTML Code:
<input type="checkbox" name="Q5C1[]" value="1" onclick="chkcontrol(0)";>
The brackets after Q5C1 will allow your checked values to be saved in an array.. so more than one value will be passed. Also, you don't need the ending </input> tag.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Last edited by thehuskybear; 09-08-2008 at 02:16 PM..
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Old 09-08-2008, 02:49 PM Re: php mailer form, multiple checkboxes
Junior Talker

Posts: 2
Name: Thom
Trades: 0
Hi,

Thanks for getting back to me, Ive tried that and in the emailed results all I get is the word Array instead of the three numbers.

Am I missing another little bit?

Thanks again
Thom
rimmet is offline
Reply With Quote
View Public Profile
 
Old 09-08-2008, 03:16 PM Re: php mailer form, multiple checkboxes
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
What you will want to do is this:

PHP Code:
$q5c1 $HTTP_POST_VARS['Q5C1'];

for (
$i=0;$i count($q5c1); $i++)
{
    switch (
$q5c1[$i])
    {
        case 
"1":
            
$mailbody .= "eDetailing";
            break;

        case 
"2":
            
$mailbody .= "eCME";
            break;
       
        
// And so on...
    
}

Basically, that gets the Q5C1 array and runs through it checking for each value and assigns text to the $mailbody variable depending on each value in the array.

You can change that around to have it formated how you want. If your not familiar with php switch, you can read about it here:

http://us2.php.net/switch

Another way of doing that would be to give each checkbox its own unique name or change the value to text...

Hope that makes sense
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Last edited by thehuskybear; 09-09-2008 at 01:14 AM..
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Old 09-08-2008, 11:50 PM Re: php mailer form, multiple checkboxes
prasanthmj's Avatar
Experienced Talker

Posts: 42
Name: Prasanth
Trades: 0
try the following changes:

1. update the check box elements to have corresponding value
<input type="checkbox" name="Q5C1[]" value="eDetailing" onclick="chkcontrol(0);"/> eDetailing

2.have a for loop to iterate through the check box array
$q5c1 = $_POST['Q5C1'];

for ($i=0;$i < count($q5c1); $i++)
{
$mailbody .= $q5c1[$i];
}

The article in the following link would be helpful
http://www.html-form-guide.com/php-f...-checkbox.html
(see the second part)

using the super global $_POST is recommended if your PHP is not too old
prasanthmj is offline
Reply With Quote
View Public Profile
 
Old 02-05-2010, 04:16 PM Re: php mailer form, multiple checkboxes
Junior Talker

Posts: 1
Name: Luciano Santa Brígida
Trades: 0
Hi, Prasanth. I've followed you exact instructions, but still didn't got my arry to print on the email. Here is how I did it:

Code:
$subject = $_POST['subject'];
function subject(){ 
	for ($i=0;$i < count($subject); $i++) {
		$mailmsg .= $subject[$i];
	};
};
$assunto = subject();

$msg=
'<p><b>Nome:</b>	'.$_POST['name'].'</p>
<p><b>IP:</b>	'.$_SERVER['REMOTE_ADDR'].'</p><br />
<h2>Assunto: '.$assunto.'</h2>'

$mail->MsgHTML($msg);
But in my email I only get "Assunto: " without the proper values in the array.

By the way, this is how the $subject array was set in the form:

Code:
<td><label for="subject">Diploma</label></td>
          <td ><input id="diploma" name="subject[]" class="validate[minCheckbox[1]] element checkbox" type="checkbox" value="Diploma" /></td>
          <td><label for="subject">Dispensa de Disciplina</label></td>
          <td ><input id="dispensa-disciplina" name="subject[]" class="validate[minCheckbox[1]] element checkbox" type="checkbox" value="Dispensa de Disciplina" /></td>
Can you help me figure out a solution for this? Thanks!
lucianosb is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php mailer form, multiple checkboxes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.25465 seconds with 12 queries