Jump to content

Recommended Posts

I have a pretty basic form mailer where I need to have the results of a multi-select box sent through the mail function.  I have used the same script before without errors, the only difference now it that I am using jQuery to submit the form instead of the form action attribute.  Does anyone know what it is that I am doing wrong here?  Here is the error I am receiving:

Warning: implode() [function.implode]: Invalid arguments passed in /usr/home/affo14/www/htdocs/home-care-information/request-home-care-processer.php on line 25

 

The form I am working on is located here:

http://www.affordablehomecare.org/home-care-information/how-to-get-home-care.html

 

My full PHP code:

<?php
/*subject and email variables*/ 
$emailSubject = 'Request Home Care';
$webMaster = 'XXXXXXX@affordablehomecare.org';

/*gathering data variables*/
$Mname = $_POST['Mname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$Btime = $_POST['Btime'];
$Cname = $_POST['Cname'];
$city = $_POST['city'];
$state = $_POST['state'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$startDate = $_POST['startDate'];
$hours = $_POST['hours'];
$days = $_POST['days'];
$list2Field = $_POST['list2'];
$extra = $_POST['extra'];
$referral = $_POST['referral'];
$list2 = implode(', ', $list2Field);

/*email field*/

$body = <<<EOD
<br><hr><br>
<h2>Contact Person</h2>
<hr>
Contact Name: $Mname <br> 	
Contact Email: $email <br>
Contact Phone Number: $phone <br>
Best to Call Around: $Btime <br>
<h2>Client Info</h2>
<hr>
Client Name: $Cname <br>
Client City: $city <br>
Client State: $state <br>
Client Age: $age <br>
Client Gender: $gender <br>
Date Service is Needed By: $startDate <br>
Days Service is Needed: $days <br>
Number of Hours Needed: $hours <br>
Client Problems: $list2 <br>
<h2>Extra Info</h2>
<hr>
Extra Info: $extra <br>
Referral Source: $referral
EOD;

/*email sender script*/
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/*results*/

print "Thank you for your interest in Affordable HomeCare.  You should expect contact from out office within 24 hours.  If you do not receive a call within 24 hours please call 800-968-8195";

?>

Link to comment
https://forums.phpfreaks.com/topic/257956-implode-errorneed-some-help/
Share on other sites

Add the following to the top of the script to see what is actually in the $_POST array. Also, you aren't doing any field validation at all. That script is wide open to email header injection, which is a spammer's wet dream.

 

echo '<pre>';
print_r($_POST);
echo '<pre>';

HTML code reads as such:

 

<select multiple name="list2[]"></select>

 

I know the script is wide open right now.  I'm just trying to get it to work correctly first.  Right now I have it set up to have jQuery to do the validation.  Aside from that the only thing I know of is reCaptcha.  From what I remember that was a fuss to get that to work properly too.  Any other suggestions on how I can prevent injection?  I'm open to any ideas as I'm sure you can see I'm pretty new to PHP.

 

 

Sorry bout not getting back to ya sooner.  So tried adding the script to the very top of the mail processor.  After adding it I do not see any results on my html form.  Before adding that script it would send the results to the form along with the implode error message.  It would even send me the email like is should it would just be missing the list2 array values.  Do you know of any other ways to diagnose the problem?

 

My hunch on why the script you wanted me to test out didn't work is because I am using jQuery to process the php instead of allowing the screen to refresh showing the php results. :-\

 

This is the jQuery I am using to process the php:

submitHandler: function(form) {
			$.post('request-home-care-processer.php', $("#requestHomeCare").serialize(), function(data) {
				$('#results').html(data);
			});
}

 

 

Nevermind....I was looking at my local copy....lol  Here are the results I get from the script you provided:

 

Array ( [Mname] => me [email] => test@testing.com [phone] => 2483200036 [btime] => never [Cname] => my mom [city] => anywhere [state] => MI [age] => 138 [gender] => Female [startDate] => 02/29/2012 [hours] => 15 hours [days] => m-w-f [extra] => please call me now [referral] => google [submit] => Send Now ) 

 

So sorry....

Array ( [Mname] => me [email] => test@testing.com [phone] => 2483200036 [btime] => never [Cname] => my mom [city] => anywhere [state] => MI [age] => 138 [gender] => Female [startDate] => 02/29/2012 [hours] => 15 hours [days] => m-w-f [extra] => please call me now [referral] => google [submit] => Send Now ) 

 

the issue is pretty self explanatory, so I will ask you.

What do you see wrong with that $_POST array?

I can see that it is not posting the list2 values but I can't figure out why.  I'm assuming it has something to do with using jquery to process the php.  If you have any ideas on a fix I would love it or if you can point me in the right direction..... 

Sorry it's so long...I tried to strip out all the unneeded stuff and just leave the form info.

 

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>How to Get Home Care in Michigan</title>
<link href="../assets/css/jquery-ui-1.8.17.custom.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script>
<script type="text/javascript" src="../assets/Scripts/js/jquery.cookie.js"></script>
<script type="text/javascript" src="../assets/Scripts/js/jquery.dropmenu.js"></script>
<script type="text/javascript" src="../assets/Scripts/js/jquery.easing.min.js"></script>
<script type="text/javascript" src="../assets/Scripts/js/jquery.cross-slide.min.js"></script>
<script type="text/javascript" src="../assets/Scripts/js/jquery.functions.js"></script>	
<script type="text/javascript" src="../assets/Scripts/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../assets/Scripts/js/additional-methods.min.js"></script>
<link href="../assets/css/style.css" rel="stylesheet" type="text/css" />
<link href="../assets/css/fonts.css" rel="stylesheet" type="text/css" />
<link href="../assets/css/form.css" rel="stylesheet" type="text/css">
<link href="../assets/css/print.css" rel="stylesheet" type="text/css" media="print" />

<script>
jQuery(document).ready(function($){			
$( '#body' ).fadeIn(400, 'easeInCirc');
$('form').removeClass('css-only');
$('#submitErr').removeClass('css-only');
});
</script>
<!-- Script for the multi select box -->
<script language="JavaScript">
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for(i=0; i<tbox.options.length; i++) {
	arrLookup[tbox.options[i].text] = tbox.options[i].value;
	arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length
for(i=0; i<fbox.options.length; i++) {
	arrLookup[fbox.options[i].text] = fbox.options[i].value;
	if(fbox.options[i].selected && fbox.options[i].value != "") {
		arrTbox[tLength] = fbox.options[i].text;
		tLength++;
	} else {
		arrFbox[fLength] = fbox.options[i].text;
		fLength++;
	}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c=0; c<arrFbox.length; c++) {
	var no = new Option();
	no.value = arrLookup[arrFbox[c]];
	no.text = arrFbox[c];
	fbox[c] = no;
}
for(c=0; c<arrTbox.length; c++) {
	var no = new Option();
	no.value = arrLookup[arrTbox[c]];
	no.text = arrTbox[c];
	tbox[c] = no;
}
}
function selectAll(box) {
for(var i=0; i<box.length; i++) {
	box.options[i].selected = true;
}
}
</script>
<script>
jQuery(document).ready(function($){	
$("#startDate").datepicker();

$("#requestHomeCare").validate({
debug: false,
messages: {
	referral: "Please tell us how you heard about us."
},
errorPlacement: function(error, element) {
		error.appendTo( element.next() );
},
submitHandler: function(form) {
			// do other stuff for a valid form
			$.post('request-home-care-processer.php', $("#requestHomeCare").serialize(), function(data) {
				$('#results').html(data);
			});
}
});
});
</script>
</head>
<body>
<!-- InstanceBeginEditable name="body-open" -->
<script type="text/javascript">
<!--//--><![CDATA[//><!--
document.write( '<div id="body">' );
//--><!]]>
</script>

    	<div id="mid-form">
        <h1>Let Us Help You</h1>
        <div class="mini">* = required</div><br>
         	<div class="formSection">
            <form action="" class="css-only" id="requestHomeCare" name="requestHomeCare" method="POST">
            	<fieldset class="rounded"><legend>Person Enquiring About Home Care</legend>
                	<dl>
                    	<dt><label for="Mname">Name:</label></dt>
					<dd><input type="text" name="Mname" id="Mname" class="text proper"/></dd>
					<dt><label for="email">* Email:</label></dt>
					<dd><input type="text" name="email" id="email" class="required email text"/><span class="errMsg"></span></dd>
                        <dt><label for="phone">* Phone:</label></dt>
					<dd><input type="text" name="phone" id="phone" class="required phoneUS text" /><span class="errMsg"></span></dd>
                        <dt><label for="Btime">Best Time to Reach You:</label></dt>
					<dd><input type="text" name="Btime" id="Btime" class="text"/></dd>
				</dl>
                </fieldset>
                <fieldset class="rounded"><legend>Person in Need of Care</legend>
                	<dl>
                		<dt><label for="Cname">Name:</label></dt>
					<dd><input type="text" name="Cname" id="Cname" class="text proper"/></dd>
                        <dt><label for="city">City:</label></dt>
					<dd><input type="text" name="city" id="city" class="text proper"/></dd>
                        <dt><label for="state">State:</label></dt>
                        <dd><select name="state" id="state" title="state" class="text">
  							<option value="null">none</option>
  							<option value="MI">Michigan</option>
  							<option value="FL">Florida</option>
  							<option value="NC">North Carolina</option>
						</select>
                        </dd>
                        <dt><label for="age">Age:</label></dt>
                        <dd><input type="text" name="age" id="age" class="text"/></dd>
                        <dt><label>Gender:</label></dt>
                        <dd>
                        <input type="radio" name="gender" value="Female" id="female"> <label for="female">Female</label><br>
					<input type="radio" name="gender" value="Male" id="male"> <label for="male">Male</label><br>
					</dd>
                	</dl>
                </fieldset>
                <fieldset class="rounded"><legend>Service Details</legend>
                	<dl>
                    	<dt><label for="startDate1">Care Needed By:</label></dt>
                        <dd><input type="text" name="startDate" id="startDate" class="text"></dd>
                        <dt><label for="hours">Hours Needed:</label></dt>
                        <dd><input type="text" name="hours" id="hours" class="text"/></dd>
                        <dt><label for="days">Days Needed:</label></dt>
                        <dd><input type="text" name="days" id="days" class="text"/></dd>                  
                    </dl>

<dl>
<dt><label>Areas of Concern: </label></dt>
<dt class="center"><table cellpadding="4" cellspacing="0" border="0">
<tr>
<td>
       <select multiple name="list1[]" title="List of possible problems" id="list1" class="list scroll">
	<OPTION VALUE="Alzheimer's">Alzheimer's</OPTION>    
    	<OPTION VALUE="Amputation">Amputation</OPTION>    
    	<OPTION VALUE="Arthritis">Arthritis</OPTION>    
    	<OPTION VALUE="Asthma">Asthma</OPTION>    
    	<OPTION VALUE="Blood Pressure">Blood Pressure</OPTION>   
    	<OPTION VALUE="Breathing">Breathing</OPTION>
        <OPTION VALUE="Broken Bone">Broken Bone</OPTION>    
    	<OPTION VALUE="Cancer">Cancer</OPTION>    
    	<OPTION VALUE="Diabetes">Diabetes</OPTION>    
   	 	<OPTION VALUE="Emphysema">Emphysema</OPTION>    
    	<OPTION VALUE="Heart Problems">Heart Problems</OPTION>    
    	<OPTION VALUE="Hospice Care">Hospice Care</OPTION>    
    	<OPTION VALUE="Osteoporosis">Osteoporosis</OPTION>    
    	<OPTION VALUE="Paralysis">Paralysis</OPTION>    
    	<OPTION VALUE="Parkinson's">Parkinson's</OPTION>    
    	<OPTION VALUE="Stroke">Stroke</OPTION>
        <OPTION VALUE="Trouble_Bathing">Trouble Bathing</OPTION> 
        <OPTION VALUE="Trouble_Dressing">Trouble Dressing</OPTION>
        <OPTION VALUE="Trouble_Feeding">Trouble Feeding</OPTION>
        <OPTION VALUE="Trouble_Standing">Trouble Standing</OPTION>    	
        <OPTION VALUE="Trouble_Toileting">Trouble Toileting</OPTION>
        <OPTION VALUE="Trouble_Walking">Trouble Walking</OPTION>
       </select><div align="center" class="details">avaliable</div>
</td>
    
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.elements['list2[]'],this.form.elements['list1[]'])" value="Remove <<" title="click to remove a concern" class="button"><br>
<input type="button" onClick="move(this.form.elements['list1[]'],this.form.elements['list2[]'])" value="Add >>" title="click to add a concern" class="button">
</td>
<td>
<select multiple name="list2[]" title="list of actual problems" class="list scroll">
</select><div align="center" class="details">selected</div>
</td>
</tr>
</table></dt>
</dt>
</fieldset>

<fieldset class="rounded"><legend>Additional Information</legend>
<dl>
	<dt><label for="extra">Extra Instructions:</label></dt>
        <dd><textarea name="extra" cols="65" rows="5" title="type any extra information you think we may need to know" id="extra"></textarea></dd>
        <dt><label for="referral">* How Do You Hear of Us:</label></dt>
        <dd><select name="referral" id="referral" title="referral source" class="required text">
              <option value="">--select one--</option>
              <option value="google">google</option>
              <option value="web_search">web search</option>
              <option value="email">email</option>
              <option value="news_paper">news paper</option>
              <option value="radio">radio</option>
              <option value="TV">TV</option>
              <option value="phone_book">phone book</option>
              <option value="van">our van</option>
              <option value="direct_mail">personal mail</option>
              <option value="senior_directory">senior directory</option>
              <option value="trade_show">trade show</option>
              <option value="hospital_directory">hospital directory</option>
              <option value="nurse">nurse</option>
              <option value="social_worker">social worker</option>
              <option value="case_manager">case manager</option>
              <option value="friend">friend</option>
              <option value="family_member">family member</option>
              <option value="AHC_Client">AHC Client</option>
              <option value="AHC_employee">AHC employee</option>
              <option value="none">none</option>
            </select>
           <span class="errMsg"></span>
	</dd>
    </dl>

</fieldset>
       <input name="submit" type="submit" value="Send Now" class="button">    
       	<div id="results"></div>
            </form>
            <span class="errMsg css-only" id="submitErr">Sorry...Javascript must be enabled in order to use the </span> 
            
       	  </div>
            
<script type="text/javascript">
<!--//--><![CDATA[//><!--
document.write( '</div><!-- body -->' );
//--><!]]>
</script>
</body>
</html>

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.