Jump to content

CHECK BOXES IN PHP CONTACT FORM NOT BEING EMAILED / DISPLAYED


cmbcorp

Recommended Posts

hi,

 

i got some issues with my contact form.

 

basically i fill in the form and it gets emailed back with all information but no check boxes are being registered.

 

Below is the code for the contact form:

<form method="post" action="sendtraining.php">			
				<p>			
				<label>Department:</label>  
				<select name="sendto">
                <option value="[email protected]" selected="selected">Training Department</option>
                    </select></label>
				<br />
				<label><span class="style1">*</span> Name</label>
				<input name="Name" value="Your Name" type="text" size="30" />
				<label><span class="style1">*</span> Company Name</label>
				<input name="Company" value="Company Name" type="text" size="30" />
				<label><span class="style1">*</span> Email</label>
				<input name="Email" value="Your Email" type="text" size="30" />
				<label><span class="style1">*</span> Phone Number</label>
				<input name="Phone" value="Your Phone Number" type="text" size="30" />
<label>Additional Training Modules </label>
<input type="checkbox" name="check[]" value="y" /> 
Reporting<br /> 
<input type="checkbox" name="check[]" value="y" />
Advanced Stock Management (Promotions, Audit trails, Deletions, Transfers etc.)<br />
<input type="checkbox" name="check[]" value="y" /> 
POS Training overview<br />
<input type="checkbox" name="check[]" value="y" />
Customer Managment (Special pricing, loyalty, customer profiling) 
<br />
<label>Other (Please specify below) </label>
				<textarea name="Message" rows="5" cols="5"></textarea>
				<br />	
				<input type="submit" name="send" value="Submit" />
				<br />
				<span class="style1">*</span>	Iindicates a 
field is required</p>		
			</form>				

 

and here is the send php file

 

<?php 
$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company'];
$phone = $_REQUEST['Phone'];  

$headers = "From: $from"; 
$subject = "RetailCare.com.au - Free Consulting Session - Conctact Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"Message"} = "Message"; 
$check_msg .= "Checked: $value\n"; 



$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A Sales representitive will be in contact with you shortly!.";

if($from=='') {print "You have not entered an email, please go back and try again";} 
if($name=='') {print "You have not entered a name, please go back and try again";} 
if($phone=='') {print "You have not entered a phone number, please go back and try again";} 
if($company=='') {print "You have not entered a company name, please go back and try again";} 

else 
{ 
$send = mail($to, $subject, $body, $check_msg, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
	if($send) 
	{
	header("Location: http://www.retailcare.com.au/thankyou.html");
	} 
	else 
	{
	echo "We encountered an error sending your mail, please notify [email protected]"; 
	}
}

?>

 

Can someone please take a look and see what im doing wrong?

 

It would be very much appreciated.

 

Thanks.

 

Jase.

You have four identical checkboxes in this form. How do you expect it to work.

 

See here

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_checkbox

 

And you're not loading data from checkboxes in your PHP script.

thanks, ok so i made each value different for each check box.

 

<form method="post" action="sendtraining.php">			
				<p>			
				<label>Department:</label>  
				<select name="sendto">
                <option value="[email protected]" selected="selected">Training Department</option>
                    </select></label>
				<br />
				<label><span class="style1">*</span> Name</label>
				<input name="Name" value="Your Name" type="text" size="30" />
				<label><span class="style1">*</span> Company Name</label>
				<input name="Company" value="Company Name" type="text" size="30" />
				<label><span class="style1">*</span> Email</label>
				<input name="Email" value="Your Email" type="text" size="30" />
				<label><span class="style1">*</span> Phone Number</label>
				<input name="Phone" value="Your Phone Number" type="text" size="30" />
<label>Additional Training Modules </label>
<input type="checkbox" name="check[]" value="Reporting" /> 
Reporting<br /> 
<input type="checkbox" name="check[]" value="Stock" />
Advanced Stock Management (Promotions, Audit trails, Deletions, Transfers etc.)<br />
<input type="checkbox" name="check[]" value="POS" /> 
POS Training overview<br />
<input type="checkbox" name="check[]" value="Customer" />
Customer Managment (Special pricing, loyalty, customer profiling) 
<br />
<label>Other (Please specify below) </label>
				<textarea name="Message" rows="5" cols="5"></textarea>
				<br />	
				<input type="submit" name="send" value="Submit" />
				<br />
				<span class="style1">*</span>	Iindicates a 
field is required</p>		
			</form>				

 

but i cant seem to get data from the check boxes in the email..

 

have i missed something in my php script?

 

I thought i was doing it right:

 

$send = mail($to, $subject, $body, $check_msg, $headers);

?

cheers for helping me on this one.

 

Look. You have these lines

$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company'];
$phone = $_REQUEST['Phone'];

they load form elements into php variables... can you spot what's missing?

thanks once again for your help.

 

i have edited the code for my php script:

 

<?php 
$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company'];
$phone = $_REQUEST['Phone']; 
$Reporting =  $_REQUEST['Reporting'];
$Stock =  $_REQUEST['Stock'];
$POS =  $_REQUEST['POS'];
$Customer =  $_REQUEST['Customer'];

$headers = "From: $from"; 
$subject = "RetailCare.com.au - Free Consulting Session - Conctact Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"Message"} = "Message"; 
$check_msg .= "Checked: $value\n"; 



$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A Sales representitive will be in contact with you shortly!.";

if($from=='') {print "You have not entered an email, please go back and try again";} 
if($name=='') {print "You have not entered a name, please go back and try again";} 
if($phone=='') {print "You have not entered a phone number, please go back and try again";} 
if($company=='') {print "You have not entered a company name, please go back and try again";} 

else 
{ 
$send = mail($to, $subject, $body, $check_msg, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
	if($send) 
	{
	header("Location: http://www.retailcare.com.au/thankyou.html");
	} 
	else 
	{
	echo "We encountered an error sending your mail, please notify [email protected]"; 
	}
}

?>

 

Still not bringing the check box values across.

 

sorry to be a no brainer, any other suggestions?

 

cheers,

ok understand. slightly.

 

i renamed the values to have their own.

 

and i agree about the check boxes.

 

is there any help you could give me and see where i have gone wrong?

 

Would really appriciate your help.

 

Thanks.

 

The problem is with your array:

 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"Message"} = "Message"; 

 

Should be:

 

$fields = array(); 
$fields["Name"] = "Name"; 
$fields["Company"] = "Company"; 
$fields["Email"] = "Email"; 
$fields["Phone"] = "Phone"; 
$fields["Message"] = "Message"; 

 

You didn't use brackets for the array indexes.

 

Also, there's a type-o in your subject line:

 

"Conctact" should be "contact"

Actually, my statement is wrong, that is not the error with your script.

 

As Mchl pointed out, the problem is with how you are loading the variables.

 

<input type="checkbox" name="check[]" value="y" />
Reporting<br />
<input type="checkbox" name="check[]" value="y" />
Advanced Stock Management (Promotions, Audit trails, Deletions, Transfers etc.)<br />
<input type="checkbox" name="check[]" value="y" />
POS Training overview<br />
<input type="checkbox" name="check[]" value="y" />

 

While these will save into the array $check and use the indexes 0-3, you won't necessarily be able to tell which is which, especially if some are checked and others are not.

 

In addition, this won't help you:

 

$Reporting =  $_REQUEST['Reporting'];
$Stock =  $_REQUEST['Stock'];
$POS =  $_REQUEST['POS'];
$Customer =  $_REQUEST['Customer'];

 

There's no form elements named "Reporting" or "Stock" or "POS" or "Customer" - they're all assigned to the $check array with this piece of HTML: name="check[]"

 

You would access them with:

 

$unknown_1 = $_REQUEST['check'][0];
$unknown_2 = $_REQUEST['check'][1];
$unknown_3 = $_REQUEST['check'][2];
$unknown_4 = $_REQUEST['check'][3];

 

Hopefully that clarifies the problem a bit?

Thanks for your help ialsoagree. I will play around with your suggestions.

 

Thanks for your help to Mchl.

 

To Mchl:

 

Here is the latest code as you requested:

 

<?php 
$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company']; 
$phone = $_REQUEST['Phone']; 
$check = $_REQUEST['check']; 
$check = implode(', ', $_REQUEST['check']); 

$headers = "From: $from"; 
$subject = "RetailCare.com.au - Free Consulting Session - Conctact Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"Message"} = "Message"; 

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b) 
{ 
$body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]); 
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A Sales representitive will be in contact with you shortly!."; 

if($from=='') {print "You have not entered an email, please go back and try again";} 
if($name=='') {print "You have not entered a name, please go back and try again";} 
if($phone=='') {print "You have not entered a phone number, please go back and try again";} 
if($company=='') {print "You have not entered a company name, please go back and try again";} 

else 
{ 
$send = mail($to, $subject, $body, $check_msg, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send) 
{ 
header("Location: http://www.retailcare.com.au/thankyou.html"); 
} 
else 
{ 
echo "We encountered an error sending your mail, please notify [email protected]"; 
} 
} 

?> 

 

 

sorry here is the latest code with your suggestions:

 

<?php 
$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company']; 
$phone = $_REQUEST['Phone']; 
$check = $_REQUEST['check']; 
$Reporting = $_REQUEST['check'][0];
$Stock = $_REQUEST['check'][1];
$POS = $_REQUEST['check'][2];
$Customer = $_REQUEST['check'][3];

$headers = "From: $from"; 
$subject = "RetailCare.com.au - Free Consulting Session - Conctact Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"Message"} = "Message"; 
$check_msg .= "Checked: $value\n";

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b) 
{ 
$body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]); 
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A Sales representitive will be in contact with you shortly!."; 

if($from=='') {print "You have not entered an email, please go back and try again";} 
if($name=='') {print "You have not entered a name, please go back and try again";} 
if($phone=='') {print "You have not entered a phone number, please go back and try again";} 
if($company=='') {print "You have not entered a company name, please go back and try again";} 

else 
{ 
$send = mail($to, $subject, $body, $check_msg, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send) 
{ 
header("Location: http://www.retailcare.com.au/thankyou.html"); 
} 
else 
{ 
echo "We encountered an error sending your mail, please notify [email protected]"; 
} 
} 

?> 
[\code]

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.