Jump to content

[SOLVED] Can't get multi values to return in a select list


scott56hannah

Recommended Posts

Hi,

 

I have a contact us form that I want to include a multi-select list to return a number of values specified by the user. Currently the html and PHP script only returns the last value selected ignoring the preceding list items selected.

 

See below the link to the Contact Us page.....followed by the PHP script

 

http://www.xlautomation.com.au/ContactUs.html

 

The $Product is the value I want to include multi values to ....

 

<?php

$FirstName 	= $_POST['FirstName'];						#assign value
$LastName 	= $_POST['LastName'];						#assign value
$Address 	= $_POST['Address'];						#assign value
$Country 	= $_POST['Country'];						#assign value
$Mobile 	= $_POST['Mobile'];							#assign value
$Phone	 	= $_POST['Phone'];							#assign value
$Email	 	= $_POST['Email'];							#assign value
$Message 	= $_POST['Message'];						#assign value
$Product 	= $_POST['ProductSelected'];				#assign value
$To			= "enquiry@xlautomation.com.au";			#recipient
$Subject	= "Contact Us Form Feedback from ".$Email;	#subject

#create the comments that will be sent as text in the message later on
$Comments	= "First Name           :".$FirstName."\n";
$Comments	.= "Last Name           :".$LastName."\n";
$Comments	.= "Address             :".$Address."\n";
$Comments	.= "Country             :".$Country."\n";
$Comments	.= "Mobile              :".$Mobile."\n";
$Comments	.= "Phone               :".$Phone."\n";
$Comments	.= "Email               :".$Email."\n";
$Comments	.= "Message             :".$Message."\n";
$Comments	.= "Products Selected   :".$Product."\n";

$Attachment	= $_FILES['ClientFile'];
$FilePath	= $_FILES['ClientFile']['tmp_name'];
$FileName	= $_FILES['ClientFile']['name'];
$FileSize	= $_FILES['ClientFile']['size'];
$FileType	= $_FILES['ClientFile']['type'];
$FileError	= $_FILES['ClientFile']['error'];

#echo "FilePath ".$FilePath."\n";
#echo "FileName ".$FileName."\n";
#echo "FileSize ".$FileSize."\n";
#echo "FileType ".$FileType."\n";
#echo "FileError ".$FileError."\n";

#make sure the file is not greater than 500k in size if it is then report the Error page for file to big
if ($FileSize > 500000)
	{
	header("Location: errors/ErrorFileSize.html");
	exit();
	}

#create a bounday string
$num			= md5(time());
$bound_text 	= "Multipart_Boundary_x{$num}x";
$bound 			= "--".$bound_text."\r\n";
$bound_last 	= "--".$bound_text."--\r\n";

#set the header information before including the text and file details
$headers 		= "From: website@xlautomation.com.au\r\n";
$headers 		.= "MIME-Version: 1.0\r\n";
$headers		.= "Content-Type: multipart/mixed; boundary=\"$bound_text\"";

#now include the text of the message before including the file
$msg 			= "If you can see this MIME than your client doesn't accept MIME types!\r\n";
$msg			.= $bound;
$msg	 		.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
  					."Content-Transfer-Encoding: 7bit\r\n\r\n"
  					.$Comments."\r\n\n"
  					.$bound;

#now set the file name for the function to return the file for sending
$file 			= file_get_contents($FilePath);

#now add the file to the message contents for sending
$msg	 		.= "Content-Type:  {$FileType}; name=\"{$FileName}\"\r\n"
  					."Content-Transfer-Encoding: base64\r\n"
					."Content-disposition: attachment; file=\"{$FileName}\"\r\n"
  					."\r\n"
  					.chunk_split(base64_encode($file))
  					.$bound_last;

#now ready to send the email
if(mail($To, $Subject, $msg, $headers))
	{
		header("Location: Thankyou.html");

	} 	else {

    	header("Location: errors/ErrorFileUpload.html");

	}

?>

Link to comment
Share on other sites

Here is the code for the Form that was linked above by http://www.xlautomation.com.au/ContactUs.html

 

The actual code of the form that is processing the script is included below.....I have cut out the full list of the countries....

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>XLAutomation - Excel Development and Consulting</title>

<meta name="keywords" content="Excel Development, Excel Programming, Excel, Software Development, Application Development, vba Development, Spreadsheet Development, Consulting">
<meta name="description" content="At XLAutomation we specialise in Excel development and consulting. We improve your business through advanced automation">
<script language="JavaScript" type="text/javascript">
function validate()
{
if(document.frm.FirstName.value == "")
{
alert("Please fill in Your First Name")
document.frm.FirstName.focus();
return false;
}
if(document.frm.LastName.value == "")
{
alert("Please fill in Your Last Name")
document.frm.LastName.focus();
return false;
}
if(document.frm.Country.value == "0")
{
alert("Please select your Country from the Drop Down List")
document.frm.Country.focus();
return false;
}
if(document.frm.Email.value == "")
{
alert("Please fill in your E-mail")
document.frm.Email.focus();
return false;
}
if(document.frm.Email.value.indexOf("@",0) < 0)
{
alert('Please enter a valid email address');
document.frm.Email.focus();
return false;
}
if(document.frm.Email.value.indexOf(".",0) < 0)
{
alert('Please enter a valid email address');
document.frm.Email.focus();
return false;
}
if(document.frm.Email.value.indexOf(" ",0) >= 0)
{
alert('Your Email cannot have spaces');
document.frm.Email.focus();
return false;
}
if(document.frm.Message.value == "")
{
alert("Please fill in Your Message")
document.frm.Message.focus();
return false;
}
if(document.frm.ClientFile.value != "")
{
var validextension = "txt,csv,xls,xlt,zip";
var extension = document.frm.ClientFile.value;
extension = extension.substring(extension.length-3,extension.length);
extension = extension.toLowerCase();
var pos = validextension.indexOf(extension);
if(pos < 0)
{
alert('You selected a file of type .'+extension+' please provide one of the valid file types listed');
document.frm.ClientFile.focus();
return false;
}
}
return true;
}
</script>
<link rel="stylesheet" type="text/css" href="styles/style.css" media="all">
</head>
<body>
<div id="masthead">
<div style="text-align: left;">
<table style="text-align: left; width: 70%; height: 120px;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 360px; height: 116px;"><a href="index.html"><img style="border: 0px solid ; width: 314px; height: 160px;" alt="XLAutomation Home Page" src="images/logo-XLAutomation.jpg"></a></td>
<td style="height: 116px; width: 572px;">
<div style="text-align: center;"></div>
<h2 class="mainpageheading" style="margin-left: 0px; width: 648px; text-align: center;">Contact
Us</h2>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div style="width: 160px;" id="leftnav">
<a class="navlink" href="index.html">Home</a>
<a href="Services.html" class="navlink">Services</a>
<a href="Products.html" class="navlink">Products</a>
<a href="Downloads.html" class="navlink">Downloads</a>
<a href="AboutUs.html" class="navlink">About Us</a>
<a href="ContactUs.html" class="navlink">Contact
Us</a>
</div>
<div id="mainContent">
<div id="articleText">
<h2>Contact Us - via Email</h2>
<p>Use the following form to contact the XLAutomation Support
team
with
questions about our products or services. Include as many details as
possible about your query so that we are able to more easily answer
your question.<br>
</p>
<p>We will endeavour to answer all questions or feedback within
24 hours.</p>
* Indicates required fields
<table style="text-align: left; width: 625px; height: 735px;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>
<form id="name" name="frm" method="post" action="Thanks.php" enctype="multipart/form-data" onsubmit="return validate();"><br>
<table style="width: 617px; height: 500px;" border="0" cellpadding="0" cellspacing="2">
<tbody>
<tr>
<td height="20" valign="middle" width="97">First Name * </td>
<td height="20" valign="middle" width="471"> <input name="FirstName" value="" size="43" type="text"></td>
</tr>
<tr>
<td height="20" valign="middle" width="97">Last Name *</td>
<td height="20" valign="middle" width="471">
<div align="left"> <input name="LastName" value="" size="43" type="text"></div>
</td>
</tr>
<tr>
<td height="20" valign="middle" width="97">Address</td>
<td height="20" valign="middle" width="471"> <input name="Address" value="" size="43" type="text"></td>
</tr>
<tr>
<td height="20" valign="middle">Country
*</td>
<td height="20" valign="middle">
<label>
<select name="Country"><option value="0"> Select the country </option><option value="Afghanistan">Afghanistan</option><option value="Albania">Albania</option><option value="Algeria">Algeria</option><option value="American">American Samoa</option><option value="Angola">Angola</option><option value="Anguilla">Anguilla</option><option value="Antartica">Antartica</option><option value="Antigua and Barbuda">Antigua
and Barbuda</option><option value="Argentina">Argentina</option><option value="Armenia">Armenia</option><option value="Aruba">Aruba</option><option value="Ashmore and Cartier Island">Ashmore
and Cartier Island</option><option value="Australia">Australia</option><option value="Austria">Austria</option><option value="Azerbaijan">Azerbaijan</option><option value="Bahamas">Bahamas</option><option value="Bahrain">Bahrain</option><option value="Bangladesh">Bangladesh</option><option value="Barbados">Barbados</option><option value="Belarus">Belarus</option><option value="Belgium">Belgium</option><option value="Belize">Belize</option><option value="Benin">Benin</option><option value="Bermuda">Bermuda</option><option value="Bhutan">Bhutan</option><option value="Bolivia">Bolivia</option><option value="Bosnia and Herzegovina">Bosnia
and Herzegovina</option><option value="Botswana">Botswana</option><option value="Brazil">Brazil</option><option value="British Virgin Islands">British
Virgin Islands</option><option value="Brunei">Brunei</option><option value="Bulgaria">Bulgaria</option><option value="Burkina Faso">Burkina Faso</option><option value="Burma">Burma</option><option value="Other">Other</option></select>
</label> </td>
</tr>
<tr>
<td height="20" valign="middle">Mobile</td>
<td height="20" valign="middle"> <input name="Mobile" value="" size="43" type="text"></td>
</tr>
<tr>
<td height="20" valign="middle" width="97">
<div align="left">Phone</div>
</td>
<td height="20" valign="middle" width="471">
<div align="left"> <input name="Phone" value="" size="43" type="text"></div>
</td>
</tr>
<tr>
<td height="20" valign="middle" width="97">
<div align="left">Email *</div>
</td>
<td height="20" valign="middle" width="471">
<div align="left"> <input name="Email" value="" size="43" type="text"></div>
</td>
</tr>
<tr>
<td height="80" valign="top" width="97">
<div align="left">Message *</div>
</td>
<td align="left" height="80" valign="top" width="471">
<label> <textarea name="Message" cols="60" rows="10"></textarea></label></td>
</tr>
<tr>
<td>Product</td>
<td><br>
If you are interested in a specific product for
download or purchase please select that product from the list below<br>
<br>
<select name="ProductSelected" size="4" multiple="yes"><option selected="selected">No product
selected</option><option>Bond Calculator</option><option>Debtors Contact System</option><option>Invoicing and Debt Tracking System</option><option>Upcoming Sellers</option></select>
<br>
</td>
</tr>
<tr>
<td><br>
<br>
Attach a file</td>
<td><br>
If you have more information, data or examples please attach a file<br>
<br>
<input name="ClientFile" value="" size="50" type="file"></td>
</tr>
<tr>
<td></td>
<td>Only files of type .txt, .csv, .xls, .xlt,
.zip, can be uploaded with this form</td>
</tr>
<tr>
<td></td>
<td>The file supplied must not exceed 500kb in size</td>
</tr>
<tr>
<td height="50" valign="top"></td>
<td align="right" height="50" valign="top"> <input value="Submit" type="submit"></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<h2>or Contact Us - via Mail</h2>
</td>
</tr>
<tr>
<td>
<div style="margin-left: 120px;"><font size="+2">XLAutomation
Development Team<br>
<br>
PO Box 257<br>
<br>
Buderim    4556<br>
<br>
Queensland<br>
<br>
Australia</font></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="footer">
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 300px;">Copyright © 2008<br>
XLAutomation <br>
All Rights Reserved<br>
<br>
Page Last Updated : January, 2008</td>
<td style="text-align: center; width: 586px;"><a class="footertext" href="PrivacyPolicy.html">Privacy
Policy</a>          <a class="footertext" href="TermsOfUse.html">Terms of Use</a></td>
<td style="text-align: right; width: 300px;"><a href="index.html"><img style="border: 0px solid ; width: 150px; height: 70px;" alt="XLAutomation Home Page" src="images/logo-XLAutomation.jpg"></a><br>
</td>
</tr>
</tbody>
</table>
</div>
</body></html>

Link to comment
Share on other sites

The problem is that, because you can select mutiple products, it returns an array of selected products. Try:

 

<?php

$FirstName 	= $_POST['FirstName'];						#assign value
$LastName 	= $_POST['LastName'];						#assign value
$Address 	= $_POST['Address'];						#assign value
$Country 	= $_POST['Country'];						#assign value
$Mobile 	= $_POST['Mobile'];							#assign value
$Phone	 	= $_POST['Phone'];							#assign value
$Email	 	= $_POST['Email'];							#assign value
$Message 	= $_POST['Message'];						#assign value
$Product 	= $_POST['ProductSelected'];				#assign value
$To			= "enquiry@xlautomation.com.au";			#recipient
$Subject	= "Contact Us Form Feedback from ".$Email;	#subject

#create the comments that will be sent as text in the message later on
$Comments	= "First Name           :".$FirstName."\n";
$Comments	.= "Last Name           :".$LastName."\n";
$Comments	.= "Address             :".$Address."\n";
$Comments	.= "Country             :".$Country."\n";
$Comments	.= "Mobile              :".$Mobile."\n";
$Comments	.= "Phone               :".$Phone."\n";
$Comments	.= "Email               :".$Email."\n";
$Comments	.= "Message             :".$Message."\n";
$Comments	.= "Products Selected   :".implode(',',$Product)."\n";

$Attachment	= $_FILES['ClientFile'];
$FilePath	= $_FILES['ClientFile']['tmp_name'];
$FileName	= $_FILES['ClientFile']['name'];
$FileSize	= $_FILES['ClientFile']['size'];
$FileType	= $_FILES['ClientFile']['type'];
$FileError	= $_FILES['ClientFile']['error'];

#echo "FilePath ".$FilePath."\n";
#echo "FileName ".$FileName."\n";
#echo "FileSize ".$FileSize."\n";
#echo "FileType ".$FileType."\n";
#echo "FileError ".$FileError."\n";

#make sure the file is not greater than 500k in size if it is then report the Error page for file to big
if ($FileSize > 500000)
	{
	header("Location: errors/ErrorFileSize.html");
	exit();
	}

#create a bounday string
$num			= md5(time());
$bound_text 	= "Multipart_Boundary_x{$num}x";
$bound 			= "--".$bound_text."\r\n";
$bound_last 	= "--".$bound_text."--\r\n";

#set the header information before including the text and file details
$headers 		= "From: website@xlautomation.com.au\r\n";
$headers 		.= "MIME-Version: 1.0\r\n";
$headers		.= "Content-Type: multipart/mixed; boundary=\"$bound_text\"";

#now include the text of the message before including the file
$msg 			= "If you can see this MIME than your client doesn't accept MIME types!\r\n";
$msg			.= $bound;
$msg	 		.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
  					."Content-Transfer-Encoding: 7bit\r\n\r\n"
  					.$Comments."\r\n\n"
  					.$bound;

#now set the file name for the function to return the file for sending
$file 			= file_get_contents($FilePath);

#now add the file to the message contents for sending
$msg	 		.= "Content-Type:  {$FileType}; name=\"{$FileName}\"\r\n"
  					."Content-Transfer-Encoding: base64\r\n"
					."Content-disposition: attachment; file=\"{$FileName}\"\r\n"
  					."\r\n"
  					.chunk_split(base64_encode($file))
  					.$bound_last;

#now ready to send the email
if(mail($To, $Subject, $msg, $headers))
	{
		header("Location: Thankyou.html");

	} 	else {

    	header("Location: errors/ErrorFileUpload.html");

	}

?>

 

I've used the implode() function to join all the elements together with a comma.

Link to comment
Share on other sites

The problem is that, because you can select mutiple products, it returns an array of selected products. Try:

 

<?php

$FirstName 	= $_POST['FirstName'];						#assign value
$LastName 	= $_POST['LastName'];						#assign value
$Address 	= $_POST['Address'];						#assign value
$Country 	= $_POST['Country'];						#assign value
$Mobile 	= $_POST['Mobile'];							#assign value
$Phone	 	= $_POST['Phone'];							#assign value
$Email	 	= $_POST['Email'];							#assign value
$Message 	= $_POST['Message'];						#assign value
$Product 	= $_POST['ProductSelected'];				#assign value
$To			= "enquiry@xlautomation.com.au";			#recipient
$Subject	= "Contact Us Form Feedback from ".$Email;	#subject

#create the comments that will be sent as text in the message later on
$Comments	= "First Name           :".$FirstName."\n";
$Comments	.= "Last Name           :".$LastName."\n";
$Comments	.= "Address             :".$Address."\n";
$Comments	.= "Country             :".$Country."\n";
$Comments	.= "Mobile              :".$Mobile."\n";
$Comments	.= "Phone               :".$Phone."\n";
$Comments	.= "Email               :".$Email."\n";
$Comments	.= "Message             :".$Message."\n";
$Comments	.= "Products Selected   :".implode(',',$Product)."\n";

$Attachment	= $_FILES['ClientFile'];
$FilePath	= $_FILES['ClientFile']['tmp_name'];
$FileName	= $_FILES['ClientFile']['name'];
$FileSize	= $_FILES['ClientFile']['size'];
$FileType	= $_FILES['ClientFile']['type'];
$FileError	= $_FILES['ClientFile']['error'];

#echo "FilePath ".$FilePath."\n";
#echo "FileName ".$FileName."\n";
#echo "FileSize ".$FileSize."\n";
#echo "FileType ".$FileType."\n";
#echo "FileError ".$FileError."\n";

#make sure the file is not greater than 500k in size if it is then report the Error page for file to big
if ($FileSize > 500000)
	{
	header("Location: errors/ErrorFileSize.html");
	exit();
	}

#create a bounday string
$num			= md5(time());
$bound_text 	= "Multipart_Boundary_x{$num}x";
$bound 			= "--".$bound_text."\r\n";
$bound_last 	= "--".$bound_text."--\r\n";

#set the header information before including the text and file details
$headers 		= "From: website@xlautomation.com.au\r\n";
$headers 		.= "MIME-Version: 1.0\r\n";
$headers		.= "Content-Type: multipart/mixed; boundary=\"$bound_text\"";

#now include the text of the message before including the file
$msg 			= "If you can see this MIME than your client doesn't accept MIME types!\r\n";
$msg			.= $bound;
$msg	 		.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
  					."Content-Transfer-Encoding: 7bit\r\n\r\n"
  					.$Comments."\r\n\n"
  					.$bound;

#now set the file name for the function to return the file for sending
$file 			= file_get_contents($FilePath);

#now add the file to the message contents for sending
$msg	 		.= "Content-Type:  {$FileType}; name=\"{$FileName}\"\r\n"
  					."Content-Transfer-Encoding: base64\r\n"
					."Content-disposition: attachment; file=\"{$FileName}\"\r\n"
  					."\r\n"
  					.chunk_split(base64_encode($file))
  					.$bound_last;

#now ready to send the email
if(mail($To, $Subject, $msg, $headers))
	{
		header("Location: Thankyou.html");

	} 	else {

    	header("Location: errors/ErrorFileUpload.html");

	}

?>

 

I've used the implode() function to join all the elements together with a comma.

 

Ok...tried that change and now the field is supplied in the email without any values included....

Did I only need to change the one line of code for the implode() function to work ?

I changed the following line....

 

$Comments .= "Products Selected  :".implode(',',$Product)."\n";

 

Thanks for your help on this....

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.