combobox returning extra line, need to filter it

Hi there, I have a combobox which returns numerals from a drop down, or reveals a text box for custom entry if ‘other’ is chosen:
e.g. 1, 2, 3, other->______

If 1 is chosen, I get back:

mytext: 1

where name is what was inside of the quotes name=“mytext”

If I choose ‘other’, then populate with 37, I get back:

mytext: other
mytext_other: 37

where the first line shows that ‘other’ was selected, and the second shows what the value of it was (note: I had to use the name, ‘mytext_other’ to get the combobox to work and avoid rewriting the output with nulls).

This then gets passed to a form as below. I need a way to filter out the “mytext: other” line as it’s unecessary, as well as ideally strip off the"_other" from the second line. Somehow I have to filter this out. I think this would be in the build function section but have no clue really.

[php]

<?php
error_reporting(E_ALL ^ E_NOTICE);
/*

The script will handle the “POST” or “GET” methods. It will also handle multiple select inputs and multiple check box inputs. If using these, you must name the field as an array using square brackets, like so: .
** PLEASE NOTE ** If you are using the script to process your own forms (or older FormToEmail forms) you must ensure that the email field is named correctly in your form, like this for example: . Note the lower case “email”. If you don’t do this, the visitor’s email address will not be available to the script and the script won’t be able to check the validity of the email, amongst other things. If you are using the form code below, you don’t need to check for this.
SETUP INSTRUCTIONS
*/
$my_email = "[email protected]";
$from_email = “Web Order”;
$continue = “…/Products.html”;
$errors = array();
// Remove $_COOKIE elements from $_REQUEST.
if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Validate email field.

if(isset($_REQUEST[‘email’]) && !empty($_REQUEST[‘email’]))
{
$_REQUEST[‘email’] = trim($_REQUEST[‘email’]);
if(substr_count($_REQUEST[‘email’],"@") != 1 || stristr($_REQUEST[‘email’]," “) || stristr($_REQUEST[‘email’],”\") || stristr($_REQUEST[‘email’],":")){$errors[] = “Email address is invalid”;}else{$exploded_email = explode("@",$_REQUEST[‘email’]);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = “Email address is invalid”;}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = “Email address is invalid”;}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = “Email address is invalid”;}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match(’/^[a-z0-9-]+$/i’,$value)){$errors[] = “Email address is invalid”; break;}}}}}}
}

// Check referrer is from same site.
if(!(isset($_SERVER[‘HTTP_REFERER’]) && !empty($_SERVER[‘HTTP_REFERER’]) && stristr($_SERVER[‘HTTP_REFERER’],$_SERVER[‘HTTP_HOST’]))){$errors[] = “You must enable referrer logging to use the form”;}

// Check for a blank form.
function recursive_array_check_blank($element_value)
{
global $set;
if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{
foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
}
}
recursive_array_check_blank($_REQUEST);
if(!$set){$errors[] = “You cannot send a blank form”;}
unset($set);

// Display any errors and exit if errors exist.
if(count($errors)){foreach($errors as $value){print “$value
”;} exit;}
if(!defined(“PHP_EOL”)){define(“PHP_EOL”, strtoupper(substr(PHP_OS,0,3) == “WIN”) ? “\r\n” : “\n”);}
// Build message.

function build_message($request_input){
if(!isset($message_output)){$message_output ="";}
if(!is_array($request_input)){$message_output = $request_input;}
else{foreach($request_input as $key => $value)
{if(!empty($value))
{if(!is_numeric($key))
{$message_output .= str_replace("_"," “,ucfirst($key)).”: “.build_message($value).PHP_EOL.PHP_EOL;}
else{$message_output .= build_message($value).”, “;}}}}
return rtrim($message_output,”, ");}

$message = build_message($_REQUEST);
$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL.“Thank you.”;
$message = stripslashes($message);
$subject = “Order Pending Confirmation”;
$subject = stripslashes($subject);
if($from_email)
{
$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST[‘email’];
}
else
{
$from_name = “”;

if(isset($_REQUEST[‘name’]) && !empty($_REQUEST[‘name’])){$from_name = stripslashes($_REQUEST[‘name’]);}
$headers = “From: {$from_name} <{$_REQUEST[‘email’]}>”;
}
mail($my_email,$subject,$message,$headers);
?>

Order Placed





Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?>
Your order has been placed.
You will receive a confirmation shortly.

Click here to continue

[/php]

-Thanks in advance for any help.

You’re building the email message based on every object in the $_REQUEST.

[php]$message = build_message($_REQUEST);[/php]

Why not just build the message the way you want it build, you can replace the line above with the line below. It might have syntax errors, I didn’t test it.

[php]
if ($_POST[‘mytext’] != ‘other’) {
$message = 'Hello you have selected: ’ . $_POST[‘mytext’];
}else {
$message = 'Hello you have selected: ’ . $_POST[‘mytext_other’];
}
[/php]

Hey, thanks again for looking.

I’ve been mostly cutting and pasting, but basically I have a list of many selectable products, say up to 100. So it would be easy if there were just a few lines.

Actually the values returned are going into an email form which will then get imported into another program. I think I can write a bash script in windows if needs be, but I’m trying to streamline this as much as possible.

I think I need to flag the $value =‘other’ and then prevent the whole line containing it from going into the build function. So far I’ve tried stringpos, if statements, and scrubbing the array afterwards. But nothing seems to work as per my abilities. I have had only completely scrubbed messages, or no change.

So just to clarify, the input comes from an html and goes to a php. I’m gonna try as you suggest anyhow and see what happens.

Okay, tried it with the variable $value instead of ‘mytext’ as it will constantly change for each row in my table. But I only got back a null message, meaning that everything got scrubbed.

I have a feeling it has something to do with it being an array variable (I think) so that if ‘other’ is in there anywhere, the if condition is triggered. I think I have to insert it somehow so that it only affects the iteration where ‘other’ is selected.

I tried removing $_POST and used $value instead.
I got back:

PHPSESSID

:o

Re-post your current PHP and HTML and the results you’re getting and I’ll look at it again.

Thanks!

Html Pt1:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Order Sheet</title>

<style type="text/css">


select, option{
    font-size:13px;
}

ol.phpfmg_form{
    list-style-type:none;
    padding:0px;
    margin:0px;
}

ol.phpfmg_form li{
    margin-bottom:5px;
    clear:both;
    display:block;
    overflow:hidden;
	width: 100%
}

.field_block_over{
}

.form_submit_block{
    padding-top: 3px;
}

.text_box, .text_area, .text_select {
    width:60px;
}

.text_area{
    height:80px;
}

div.col_label{
    float:left;
    width:100%;
    text-align: left;
}

div.col_field{
	margin-left:15px;
	width:-50px;
	float:right;
}

li { background: silver; } 
li:nth-child(odd) { background: white; } 
    
</style>


<script type="text/javascript" src="../js/siteUtil.js"></script>
	<script type="text/javascript">
sfHover = function() {
var el = document.getElementById('Nav1');
if(!/\bnav\b/.test(el.className) && el.tagName == 'UL')
setHover(el);
var ieNavs = document.getElementsByTagName('ul');
for(i=0; i<ieNavs.length; i++) {
var ul = ieNavs[i]; if(/\bnav\b/.test(ul.className))
setHover(ul); }} 
function setHover(nav) {
var ieULs = nav.getElementsByTagName('ul');
if (navigator.appVersion.substr(22,3)!='5.0') {
for (j=0; j<ieULs.length; j++) {
var ieMat=document.createElement('iframe');
if(document.location.protocol == 'https:')
ieMat.src='';
else if(window.opera != 'undefined')
ieMat.src='';
else
ieMat.src='javascript:false';
ieMat.scrolling='no';
ieMat.frameBorder='0';
ieMat.style.width=ieULs[j].offsetWidth+'px';
ieMat.style.height=ieULs[j].offsetHeight+'px';
ieMat.style.zIndex='-1';
ieULs[j].insertBefore(ieMat, ieULs[j].childNodes[0]);
ieULs[j].style.zIndex='101';
}
var ieLIs = nav.getElementsByTagName('li');
for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
ieLIs[i].onmouseover=function() {
if(!/\bsfhover\b/.test(this.className))
this.className+=' sfhover';
}
ieLIs[i].onmouseout=function() {
if(!this.contains(event.toElement))
this.className=this.className.replace(' sfhover', '');
}
ieLIs[i].onmouseclick=function() {
if(!this.contains(event.toElement))
this.className=this.className.replace(' sfhover', '');
}
}
}
}
if(window.attachEvent) window.attachEvent('onload', sfHover);
	</script>

    <link rel="stylesheet" type="text/css" id="layout1.css" href="../css/layout1.css">
    <link rel="stylesheet" type="text/css" id="theme.css" href="../css/theme.css">
    <link rel="stylesheet" type="text/css" id="color_1.css" href="../css/color_1.css">
    <link rel="stylesheet" type="text/css" id="custom.css" href="../css/custom.css">
    
<script id="widgetbox_lib_subscriber_main" type="text/javascript" async="true" src="../js/Main.js"></script><script id="widgetbox_getwidgetinfo_script_140543b6-862b-4218-8d8a-adbba031261e" type="text/javascript" async="true" src="../js/get_widget.js"></script>

<style id="wrc-middle-css" type="text/css">
.wrc_whole_window{	display: none;	position: fixed; 	z-index: 2147483647;	background-color: rgba(40, 40, 40, 0.9);	word-spacing: normal;	margin: 0px;	padding: 0px;	border: 0px;	left: 0px;	top: 0px;	width: 100%;	height: 100%;	line-height: normal;	letter-spacing: normal;}.wrc_middle_main {	font-family: Segoe UI, Arial Unicode MS, Arial, Sans-Serif;	font-size: 14px;	width: 600px;	height: auto;	margin: 0px auto;	margin-top: 15%;    background: url(chrome-extension://icmlaeflemplmjndnaapfdbbnpncnbda/skin/images/background-body.jpg) repeat-x left top;	background-color: rgb(39, 53, 62);}.wrc_middle_logo {    background: url(chrome-extension://icmlaeflemplmjndnaapfdbbnpncnbda/skin/images/logo.jpg) no-repeat left bottom;    width: 140px;    height: 42px;    color: orange;    display: table-cell;    text-align: right;    vertical-align: middle;}.wrc_icon_warning {	margin: 20px 10px 20px 15px;	float: left;	background-color: transparent;}.wrc_middle_title {    color: #b6bec7;	height: auto;    margin: 0px auto;	font-size: 2.2em;	white-space: nowrap;	text-align: center;}.wrc_middle_hline {    height: 2px;	width: 100%;    display: block;}.wrc_middle_description {	text-align: center;	margin: 15px;	font-size: 1.4em;	padding: 20px;	height: auto;	color: white;	min-height: 3.5em;}.wrc_middle_actions_main_div {	margin-bottom: 15px;	text-align: center;}.wrc_middle_actions_blue_button {	-moz-appearance: none;	border-radius: 7px;	-moz-border-radius: 7px/7px;	border-radius: 7px/7px;	background-color: rgb(0, 173, 223) !important;	display: inline-block;	width: auto;	cursor: Pointer;	border: 2px solid #00dddd;}.wrc_middle_actions_blue_button:hover {	background-color: rgb(0, 159, 212) !important;}.wrc_middle_actions_blue_button:active {	background-color: rgb(0, 146, 200) !important;	border: 2px solid #00aaaa;}.wrc_middle_actions_blue_button div {	display: inline-block;	width: auto;	cursor: Pointer;	margin: 3px 10px 3px 10px;	color: white;	font-size: 1.2em;	font-weight: bold;}.wrc_middle_action_low {	font-size: 0.9em;	white-space: nowrap;	cursor: Pointer;	color: grey !important;	margin: 10px 10px 0px 10px;	text-decoration: none;}.wrc_middle_action_low:hover {	color: #aa4400 !important;}.wrc_middle_actions_rest_div {	padding-top: 5px;	white-space: nowrap;	text-align: center;}.wrc_middle_action {	white-space: nowrap;	cursor: Pointer;	color: red !important;	font-size: 1.2em;	margin: 10px 10px 0px 10px;	text-decoration: none;}.wrc_middle_action:hover {	color: #aa4400 !important;}body,td,th {
	font-size: 11px;
}
.headingsmaltext {
	font-size: 11px;
}
#page_946f409e-e5c4-481a-ab97-8c570c6ed865 .sf_outer_wrapper .sf_wrapper .sf_main_wrapper .sf_main .sf_region6 .sf_content div #content1 div {
	font-size: 18px;
}
</style>

<script id="wrc-script-middle_window" type="text/javascript" language="JavaScript">var g_inputsCnt = 0;var g_InputThis = new Array(null, null, null, null);var g_alerted = false;/* we test the input if it includes 4 digits   (input is a part of 4 inputs for filling the credit-card number)*/function is4DigitsCardNumber(val){	var regExp = new RegExp('[0-9]{4}');	return (val.length == 4 && val.search(regExp) == 0);}/* testing the whole credit-card number 19 digits devided by three '-' symbols or   exactly 16 digits without any dividers*/function isCreditCardNumber(val){	if(val.length == 19)	{		var regExp = new RegExp('[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}');		return (val.search(regExp) == 0);	}	else if(val.length == 16)	{		var regExp = new RegExp('[0-9]{4}[0-9]{4}[0-9]{4}[0-9]{4}');		return (val.search(regExp) == 0);	}	return false;}function CheckInputOnCreditNumber(self){	if(g_alerted)		return false;	var value = self.value;	if(self.type == 'text')	{		if(is4DigitsCardNumber(value))		{			var cont = true;			for(i = 0; i < g_inputsCnt; i++)				if(g_InputThis[i] == self)					cont = false;			if(cont && g_inputsCnt < 4)			{				g_InputThis[g_inputsCnt] = self;				g_inputsCnt++;			}		}		g_alerted = (g_inputsCnt == 4);		if(g_alerted)			g_inputsCnt = 0;		else			g_alerted = isCreditCardNumber(value);	}	return g_alerted;}function CheckInputOnPassword(self){	if(g_alerted)		return false;	var value = self.value;	if(self.type == 'password')	{		g_alerted = (value.length > 0);	}	return g_alerted;}function onInputBlur(self, bRatingOk, bFishingSite){	var bCreditNumber = CheckInputOnCreditNumber(self);	var bPassword = CheckInputOnPassword(self);	if((!bRatingOk || bFishingSite == 1) && (bCreditNumber || bPassword) )	{		var warnDiv = document.getElementById("wrcinputdiv");		if(warnDiv)		{			/* show the warning div in the middle of the screen */			warnDiv.style.left = "0px";			warnDiv.style.top = "0px";			warnDiv.style.width = "100%";			warnDiv.style.height = "100%";			document.getElementById("wrc_warn_fs").style.display = 'none';			document.getElementById("wrc_warn_cn").style.display = 'none';			if(bFishingSite)				document.getElementById("wrc_warn_fs").style.display = 'block';			else				document.getElementById("wrc_warn_cn").style.display = 'block';			warnDiv.style.display = 'block';		}	}}</script>


</head>
<body id="page_946f409e-e5c4-481a-ab97-8c570c6ed865">

<div class="sf_outer_wrapper">
	<div class="sf_region1">
		
	</div>
	<div class="sf_extra1"><span></span></div>
	<div class="sf_wrapper"><div style="display:block;overflow:visible;margin:0;padding:0;"><div class="sf_undocked" style="display:block;height:0;position:absolute;margin:0;padding:0;overflow:visible;width:0;top:0;z-index:999998;left:auto;">
</div></div>

		<div class="sf_region2">
			<div class="sf_navigation"><div class="widget main_nav"><h3 class="widget_header"><span>Main Navigation</span></h3><div class="widget_content"><div style="display:block;">
</div></div></div></div>
		</div>
		<div class="sf_extra10"><span></span></div>
		<div class="sf_header_wrapper">
			<div class="sf_extra2"><span></span></div>
			<div class="sf_region3">
				<div class="sf_main_header"><div style="display:block;">Distribution</div></div>
			</div>
			<div class="sf_extra3"><span></span></div>
		</div>
		<div class="sf_extra4"><span></span></div>
		<div class="sf_region4">
			<div class="sf_pagetitle"><div style="display:block;"><h1>ORDER</h1></div></div>
		</div>
		<div class="sf_extra5"><span></span></div>
		<div class="sf_region5">
			
		</div>
		<div class="sf_extra6"><span></span></div>
		<div class="sf_extra11"><span></span></div>
		<div class="sf_main_wrapper">
			<div class="sf_main">
				<div class="sf_region6">
					<div class="sf_content"><div style="display:block;zoom:1"><div id="content1"><div style="display:block;"><div style="display:block;">

<div class="form_description">

</div>

<form name="FormToEmail.php" action="./FormToEmail.php" method="post" >
            
<ol class="phpfmg_form">
<!--ul id="myList"-->

<li class="field_block" id="field_94_div"><div class="col_label"><label class="form_field">389       KSC-001Salt</label><label class="form_required">&nbsp;</label><div class="col_field"> 
            	<select name="389KSC-001Salt" id="field_94" class="text_select" onchange="toggleOtherInputBox(&#39;field_94&#39;,&#39;select&#39;,&#39;field_94&#39;);">

<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="20">20</option><option value="50">50</option><option value="100">100</option><option value="500">500</option><option value="1000">1000</option> <option value="other">other</option> </select>

<input type="hidden" name="389KSC-001SaltOTHER" id="field_94_other_check" value="0"> 
<br id="field_94_other_br">
<input type="text" name="389KSC-001SaltOTHER" id="field_94_other" value="" style="display: none; " class="text_box"> 
<div id="field_94_tip" class="instruction"> 

</div> </div> </div></li>
<!--/ul-->

<center>
<table border="0"  width="90%" style="background-color: #F3F2ED;" cellspacing="5">
<!--tr align="left"><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
<tr align="left"><td>Email address</td><td><input type="text" size="30" name="email"></td></tr-->
<input type="hidden" name= "name" value="Porchetta" />
<tr align="left"><td valign="top">Comments</td><td align="left"><textarea name="comments" rows="3" cols="40"></textarea></td></tr>
<tr align="left"><td>&nbsp;</td><td><input type="submit" value="Send"></td></tr>
</table></center>

</ol>
</form>

<script type="text/javascript">
 /**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

 function dd_change( n, max, prefix ){
    if( n >= max-1 )
        return; // the last dropdown, no need to query
    
    //var prefix = 'dd_' ;
    // reset all other dropdown options
    var next = n+1; 
    for( var i = next; i < max; i ++ ){
        var dd = document.getElementById(prefix +'_' + i );
        if( dd && dd.length >= 1 ) dd.length = 1 ; // keep the first one '- select -'
    };

Html pt.2:

[code] // request drop down data from server
var me = this;
var http;
var isIE = navigator.appName == “Microsoft Internet Explorer”;
if(isIE){
me.http = new ActiveXObject(“Microsoft.XMLHTTP”);
}else{
me.http = new XMLHttpRequest();
};

// build query string
var lookup = [];
for( var i = 0; i < next; i ++ ){
    var v = document.getElementById(prefix +'_' +  i ).value ; 
    lookup.push( "lookup[" + i + "]=" + escape( isIE ? Utf8.encode(v) : v ) );
};
lookup = lookup.join('&');

var url = 'admin.php?mod=dd&func=lookup&n='+next+ '&field_name=' + prefix + '&' + lookup;
me.http.open('get', url);
me.http.onreadystatechange = function(){

    if( me.http.readyState == 4 ){
        // rebuild the next dropdown options
        var eNext = document.getElementById(prefix +'_' + next );
        if( !eNext )
            return;
        
        var data = me.http.responseText;    
        var opts = String(data).split("\n");
        for( var j = 0, J = opts.length; j < J; j ++ ){
            eNext.options[ eNext.length ] = new Option( opts[j], opts[j], false, false );                
        }; // for
    }; //if
    
}; 
me.http.send(null);

}

function PHPFMG( formID ){
var frmID = formID;
var exts = {
‘upload_control’ : ‘’,
‘harmful_exts’ : ‘.php, .html, .css, .js, .exe, .com, .bat, .vb, .vbs, scr, .inf, .reg, .lnk, .pif, .ade, .adp, .app, .bas, .chm, .cmd, .cpl, .crt, .csh, .fxp, .hlp, .hta, .ins, .isp, .jse, .ksh, .Lnk, .mda, .mdb, .mde, .mdt, .mdw, .mdz, .msc, .msi, .msp, .mst, .ops, .pcd, .prf, .prg, .pst, .scf, .scr, .sct, .shb, .shs, .url, .vbe, .wsc, .wsf, .wsh’,
‘harmful_errmsg’: “File is potential harmful. Upload is not allowed.”,
‘allow_exts’ : ‘.jpg, .gif, .png, .bmp’,
‘allow_errmsg’: “Upload is not allowed. Please check your file type.”
};

var Form = null;
var err_fields=null;

function $( id ){
    return document.getElementById(id);
}

function get_form( id ){
    var frm = 'object' == typeof($(id)) ? $(id) : eval( 'document.' + id ) ;
    return frm ? frm : document.forms[0];
}

function file_ext( f ){
    var n = f.lastIndexOf(".");
    return -1 == n ? '' : f.substr( n ).toLowerCase();
}

function addLabelEvents(){
    var labels = document.body.getElementsByTagName('LABEL');
    for( var i = 0, N = labels.length; i < N; i ++ ){
        var e = labels[i];
        if( -1 != String(e.className).indexOf('form_choice_text') ){
            var oid = e.getAttribute('oid'); 
            if( !oid ) continue;

            e.onmouseout = function(){ this.className = 'form_choice_text'; };
            e.onmouseover = function(){ this.className = 'form_choice_text form_choice_over'; };
            e.onclick = function(){
                try{
                    var oid = this.getAttribute('oid'); 
                    var O = document.getElementById(oid);
                    O.checked = !O.checked;
                }
                catch(E){};
            };
        }; // if
    }; // for
} 


function addFieldBlockEvents(){
    var divs = document.body.getElementsByTagName('DIV');
    for( var i = 0, N = divs.length; i < N; i ++ ){
        var e = divs[i];
        if( -1 != String(e.className).indexOf('field_block') ){
            e.onmouseout = function(){  if( String(this.className).indexOf('form_error_highlight') == -1 ) this.className = 'field_block'; };
            e.onmouseover = function(){ if( String(this.className).indexOf('form_error_highlight') == -1 ) this.className = 'field_block field_block_over'; };
        }; // if
    }; // for
} 

function removeHighlight( elements ){
    var divs = typeof(elements) == 'object' ? elements : document.body.getElementsByTagName('DIV');
    for( var i = 0, N = divs.length; i < N; i ++ ){
        var e = divs[i];
        var cn = String(e.className);
        if( -1 != cn.indexOf('form_error_highlight') ){
            e.className = cn.replace('form_error_highlight','');
        }; // if
    }; // for
} 

function showProcessing(){
    try{
        var E = $('phpfmg_processing');
        if( !E ) return ;
        if( -1 != navigator.userAgent.toLowerCase().indexOf('msie') ){
            E.style.backgroundColor='#2960AF';
            $('phpfmg_processing_gif').style.display = 'none';
            setInterval( 'fmgHandler.dots()', 380 );
        };
        E.style.display = '' ;
    }catch(e){};
    
}


this.highlight_fields = function( fields ){
    var A = fields.split(',');
    for( var i = 0, N = A.length; i < N; i ++ ){
        var E = $( A[i] + '_div' );
        if( E ){
            E.className += ' form_error_highlight'; 
        };
        var T = $( A[i] + '_tip' );
        if( T ){
            T.className += ' instruction_error'; 
        };
    };
    
    if( A.length > 0 ) {
        $('err_required').style.display= has_entry( fields ) ? 'none' : '';
    };
}

function has_entry( fields ){
    var div = $('one_entry_msg'); 
    if( !div )
        return false;

    div.style.display = fields.indexOf('phpfmg_found_entry') != -1 ? '' : 'none';
    if( typeof(found_entry) != 'undefined' ){
        div.innerHTML = div.innerHTML.replace(/%Entry%/gi,found_entry);
        return true;
    };
    
    return false ;
}


this.choice_clicked = function( id ){
    $(id).checked = !$(id).checked ;
}


this.init = function(){
    //addLabelEvents();
    addFieldBlockEvents();
}

this.harmful = function(e){
    if( 'deny' != exts['upload_control'] || e.value == '' ){
        return true; 
    };
    
    var div = $(e.id+'_div');
    removeHighlight( [div] );
    var ext = file_ext(e.value);
    if( -1 != exts['harmful_exts'].toLowerCase().indexOf(ext) ){
        this.highlight_fields(e.id);
        alert( exts['harmful_errmsg'] );
        return false ;
    };
    return true;
}

 
    
this.is_allow = function(e){
    if( 'allow' != exts['upload_control'] || e.value == '' ){
        return true; 
    };
    
    var div = $(e.id+'_div');
    removeHighlight( [div] );
    var ext = file_ext(e.value);
    if( -1 == exts['allow_exts'].toLowerCase().indexOf(ext) ){
        this.highlight_fields(e.id);
        alert( exts['allow_errmsg'] );
        return false ;
    };
    return true;
} 

this.check_upload = function(e){
    if( '' == exts['upload_control'] )
        return true;
    else
        return ( 'deny' == exts['upload_control'] ) 
               ? this.harmful(e) 
               : this.is_allow(e);
}

this.dots = function(){
    $('phpfmg_processing_dots').innerHTML += '.';
	if( $('phpfmg_processing_dots').innerHTML.length >= 38 ) {
		$('phpfmg_processing_dots').innerHTML = '.';
	};
}

this.check_fields = function(){
    if( !Form )
        return true ;

    var pass = true ;
    for( var i=0, n=Form.elements.length; i < n ; i ++ ){
      var field = Form.elements[i];
      var type = field.length != undefined && field.type == undefined ? 'radio' : field.type ;
      switch( type.toLowerCase() ){
        case 'file':
            pass = this.check_upload(field);
            break;
      };
      if( !pass ) return false ;
    };
    
    return true;
}

this.onsubmit = function( form ){
    Form = form ? form : get_form(frmID) ;
    if( !this.check_fields() )
        return false ;
        
    showProcessing();
    return true;
}

}

function toggleOtherInputBox( name, type, id ){
var field = document.getElementById(id);
if( !field ) return ;
var box = document.getElementById(name+’_other’);
var other_check = document.getElementById(name+’_other_check’);
if( !box || !other_check ) return ;

switch( type.toLowerCase() ){
    case 'checkbox':
        box.style.display = field.checked ? '' : 'none';
        other_check.value = field.checked ? 1 : 0 ; 
        break;
    case 'radio':
        for( var i=0,n=document.forms.length; i < n; i ++ ){
            try{
                var r = eval( 'document.forms['+i+'].'+name );
                if( r ){
                    box.style.display = r[r.length-1].checked ? '' : 'none';
                    other_check.value = r[r.length-1].checked ? 1 : 0 ; 
                };
            }catch(err){};
        };
        break;
    case 'select':
        box.style.display = field.options[field.options.length-1].selected ? '' : 'none';
        other_check.value = field.options[field.options.length-1].selected ? 1 : 0 ;
        break;
};

}

var fmgHandler = new PHPFMG();
fmgHandler.init();

	</div>
	<div class="sf_region8">
		
	</div>
	<!-- 7 -->
	<div class="sf_region9" align="center">
		<div class="sf_footer"><div style="display:block;"><div style="text-align: center;">&nbsp;
		  <div align="center">Content copyright 
		    <script type="text/javascript">if (typeof(getCopyrightDate)=='function') document.write(getCopyrightDate(2012, null, '-')); else document.write((new Date()).getFullYear());</script>
		    . CANWAYDISTRIBUTION.COM. All rights reserved.
		    <script type="text/javascript" src="../js/InsertWidget.js"></script>
		    <script type="text/javascript" language="javascript">if (WIDGETBOX) WIDGETBOX.renderWidget("140543b6-862b-4218-8d8a-adbba031261e", true);</script>
		  </div>
	    <div id="widgetbox_widget_parent_0" style="line-height:0"><div id="widgetbox_widget_div_0"></div></div></div></div></div>
	</div>
</div>
<!-- /sf_wrapper -->
[/code]

[php] <?php

error_reporting(E_ALL ^ E_NOTICE);

/*


The script will handle the “POST” or “GET” methods. It will also handle multiple select inputs and multiple check box inputs. If using these, you must name the field as an array using square brackets, like so: .

** PLEASE NOTE ** If you are using the script to process your own forms (or older FormToEmail forms) you must ensure that the email field is named correctly in your form, like this for example: . Note the lower case “email”. If you don’t do this, the visitor’s email address will not be available to the script and the script won’t be able to check the validity of the email, amongst other things. If you are using the form code below, you don’t need to check for this.

SETUP INSTRUCTIONS
*/

$my_email = "[email protected]";
$from_email = “Web Order”;
$continue = “…/Products.html”;

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Validate email field.

if(isset($_REQUEST[‘email’]) && !empty($_REQUEST[‘email’]))
{

$_REQUEST[‘email’] = trim($_REQUEST[‘email’]);

if(substr_count($_REQUEST[‘email’],"@") != 1 || stristr($_REQUEST[‘email’]," “) || stristr($_REQUEST[‘email’],”\") || stristr($_REQUEST[‘email’],":")){$errors[] = “Email address is invalid”;}else{$exploded_email = explode("@",$_REQUEST[‘email’]);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = “Email address is invalid”;}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = “Email address is invalid”;}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = “Email address is invalid”;}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match(’/^[a-z0-9-]+$/i’,$value)){$errors[] = “Email address is invalid”; break;}}}}}}

}

// Check referrer is from same site.

if(!(isset($_SERVER[‘HTTP_REFERER’]) && !empty($_SERVER[‘HTTP_REFERER’]) && stristr($_SERVER[‘HTTP_REFERER’],$_SERVER[‘HTTP_HOST’]))){$errors[] = “You must enable referrer logging to use the form”;}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = “You cannot send a blank form”;}

unset($set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print “$value
”;} exit;}

if(!defined(“PHP_EOL”)){define(“PHP_EOL”, strtoupper(substr(PHP_OS,0,3) == “WIN”) ? “\r\n” : “\n”);}

// Build message.

function build_message($request_input){

if(!isset($message_output)){$message_output ="";}

if(!is_array($request_input)){$message_output = $request_input;}

else{foreach($request_input as $key => $value)

{if(!empty($value))

{if(!is_numeric($key))

{$message_output .= str_replace("_"," “,ucfirst($key)).”: ".build_message($value).PHP_EOL.PHP_EOL;}

else{$message_output .= build_message($value).", ";}}}}

return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL.“Thank you.”;

$message = stripslashes($message);

$subject = “Order Pending Confirmation”;

$subject = stripslashes($subject);

if($from_email)
{

$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST[‘email’];

}
else
{

$from_name = “”;

if(isset($_REQUEST[‘name’]) && !empty($_REQUEST[‘name’])){$from_name = stripslashes($_REQUEST[‘name’]);}

$headers = “From: {$from_name} <{$_REQUEST[‘email’]}>”;

}

mail($my_email,$subject,$message,$headers);

?>

Order Placed





Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?>
Your order has been placed.
You will receive a confirmation shortly.

Click here to continue

[/php]

Now that I got to see a little more of your HTML and forgive me I’m very tired, so I really didn’t analyze everything…

I see two instances where you have the same name assigned

[php]

[/php]

And

[php]
[/php]

Technically, this is illegal and on the post back it will return the first one it’s finds, so it’s always going to be “porchetta” and “0” for the $_request[“name”] and $_request[“389KSC-001SaltOTHER”]

If you wanted to make it an array you would add brackets to it like below, but I really don’t understand why you have the same named hidden fields to begin with.

[php]

[/php]

Then you can retrieve each of two elements in a foreach loop.

Thanks Topcoder for helping so much!

I’m not sure exactly why the variables had to be duplicated, but for some reason if they were not, nothing was returned.

I did not use an array as you suggested, but in the end, I played around with my build function to weed out the lower case ‘other’ and trim off the upper case ‘OTHER’ so that I got the desired result. This was in the scope of my understanding so I chose this route.

I very much appreciate your help and will revisit this again.

Sponsor our Newsletter | Privacy Policy | Terms of Service