checkbox not working

wrw28 17 Apr, 2009
Hi:

Version is ChronoContact 3.1 RC4
Joomla 1.5.9
PHP5
MySQL 5.0.41

I tested the form and php process file outside of the joomla installation. It worked w/out a problem. I take the same code and install in Chronocontact and add the same processing code to either the before email submit or after email submit and the checkbox data is never stored. I have turned on debug and the values are available in the $_POST array:

Debug Array

Array ( [company] => [firstname] => Destin [lastname] => Bree [email] => [email]bree@gmail.com[/email] [telephone] => [refwebsite] => [Services] => Array ( [0] => WebDesign [1] => ecommerce ) [projectTitle] => Destin [prjDescription] => new site [projectBudget] => $1,000 - $1,999 [numPages] => 20 [website] => [Website_ex1] => http://www. [Website_ex2] => http://www. [Website_ex3] => http://www. [moreInfo] => new site [btnSubmit] => Request Quote [05d0a04b57bdd0af37ada674ea2f0349] => 1 ) Destin
Warning: Invalid argument supplied for foreach() in H:\xampp\htdocs\epicbay2\components\com_chronocontact\libraries\customcode.php(42) : eval()'d code on line 33
SQL Project:INSERT INTO project_details(contact_id, mdate, Services, ProjectTitle, Description, Budget, WebPages, RefWebsite, Competitor1, Competitor2, Competitor3, Notes)VALUES ('26', '04/16/2009', '', 'Destin', 'new site', '$1,000 - $1,999', '20', '', 'http://www.', 'http://www.', 'http://www.', 'new site')




If I check whether "Services" is an array--the foreach loop never executes--thus saying it is not an array. Note: All other values are correctly stored to db. I'm confused, because this code executed fine as standalone code on the same server. The only difference is the php code was used as the "action" of the form. Any help would be greatly appreciated.
/*-----------------PHP Processing code--------------------------------------------*/

$connection = mysql_connect("localhost","root",""); 
	if (!$connection) {
		die("Database connection failed: " . mysql_error());
	}

	// 2. Select a database to use 
	$db_select = mysql_select_db("myDB",$connection);
	if (!$db_select) {
		die("Database selection failed: " . mysql_error());
	}
 function makeValue($val) {
			$newVal = trim(htmlspecialchars($val));
			return $newVal;
	}
	
//Get database values
//Contact
$first = makeValue($_POST["firstname"]);
echo $first;
$last = makeValue($_POST["lastname"]);
$eMail = makeValue($_POST["email"]);
$sql = "INSERT INTO names (FirstName, LastName, email)";
$sql .= "VALUES('$first','$last','$eMail') ON DUPLICATE KEY UPDATE contact_id = last_insert_id(contact_id)";
if (!mysql_query($sql,$connection))
  {
  die('Names Error: ' . mysql_error());
  }
// Prepare vars  
$lastId = mysql_insert_id();
$currentDate = date("m/d/Y");
foreach($_POST['Services'] as $service) {
	$service = makeValue($service);
	$reqServices .= $service.' ';
}
$prjTitle = makeValue($_POST["projectTitle"]); 
$prjDesc = makeValue($_POST["prjDescription"]);
$prjBudget = makeValue($_POST["projectBudget"]);
$prjPages = makeValue($_POST["numPages"]);
$currSite = makeValue($_POST["website"]);
$web1 = makeValue($_POST["Website_ex1"]);
$web2 = makeValue($_POST["Website_ex2"]);
$web3 = makeValue($_POST["Website_ex3"]);
$theNotes = makeValue( $_POST["moreInfo"]);

$sql = "INSERT INTO project_details(contact_id, mdate, Services, ProjectTitle, Description, Budget, WebPages, RefWebsite, Competitor1, Competitor2, Competitor3, Notes)";
$sql .= "VALUES ('$lastId', '$currentDate', '$reqServices', '$prjTitle', '$prjDesc', '$prjBudget', '$prjPages', '$currSite', '$web1', '$web2', '$web3', '$theNotes')";
echo "SQL Project:".$sql;
if (!mysql_query($sql,$connection))
  {
  die('Project Error: ' . mysql_error());
  }
 $thePhone = makeValue( $_POST["telephone"]);
 $sql = "INSERT INTO telephones(contact_id, TelephoneCell, TelephoneWork)";
 $sql .= "VALUES('$lastId', ' ', '$thePhone')";
 if (!mysql_query($sql,$connection))
  {
  die('Phone Error: ' . mysql_error());
  }
  $theCompany = makeValue( $_POST["company"]);
  $theWebsite = makeValue( $_POST["refwebsite"]);
 $sql = "INSERT INTO company_details(contact_id, CompanyName, Designation, WebSite)";
 $sql .= "VALUES('$lastId', '$theCompany', ' ', '$theWebsite')";
 if (!mysql_query($sql,$connection))
  {
  die('Company Error: ' . mysql_error());
  }
mysql_close($connection);
----Snip end processing code-----------------------
/------------------Snippet form check box---------------------------------------/

<fieldset class="formQuote">
<span class="formQuote">
  <legend>Services Desired</legend>
     <label>
       <input type="checkbox" name="Services[]" value="logo" id="Services_0" />
       Logo</label>
     <br />
     <label>
       <input type="checkbox" name="Services[]" value="GraphicDesign" id="Services_1" />
       Graphic Design</label>
     <br />
     <label>
       <input type="checkbox" name="Services[]" value="WebDesign" id="Services_2" />
       Website Design</label>
     <br />
      <label>
       <input type="checkbox" name="Services[]" value="ecommerce" id="Services_6" />
       E-Commerce</label>
     <br />
     <label>
       <input type="checkbox" name="Services[]" value="CMS" id="Services_3" />
       Content Management System (CMS)</label>
     <br />
     <label>
       <input type="checkbox" name="Services[]" value="SEO" id="Services_4" />
       Search Engine Optimization (SEO)</label>
     <br />
     <label>
       <input type="checkbox" name="Services[]" value="programming" id="Services_5" />
       Programming</label>
     <br />
     <label>
       <input type="checkbox" name="Services[]" value="techWrite" id="Services_7" />
       Technical Writing/Manuals</label>
     <br />
</span>
  </fieldset>

/*--------------------------------end checkbox html---------------------*/
GreyHead 17 Apr, 2009
HI ww28,

There is a bug in the currnet release that only handles arrays correctly if Emails are enabled in the General tab. Max has fixed this for the next release, meanwhile just set Emails on (even though you aren't using any) and all should be OK.

Bob
This topic is locked and no more replies can be posted.