php array from database

Participant

php array from database

I don't want to use a form for adding contacts from our website. I'm just going to call data from a couple of tables and process it to CC once a day, so no POSTED values.  I only need 'custom_field_2', which will have a dynamic value ($var), and all the other custom fields will have a nothing value.

How can I express the custom fields array?  (This:  $postFields["custom_fields"] = array() )

 

Is this anywhere close (tried it - doesn't work):

<?php 
   $postFields["custom_fields"] = array(1=>'', 2=>'$var', 3=>'', 4=>''....);
?>

or this (tried it - doesn't work):

<?php
  $postFields["custom_fields"][1] = '';
  $postFields["custom_fields"][2] = '$var';
  $postFields["custom_fields"][3] = '';
  $postFields["custom_fields"][4] = '';
?>

 

My head hurts much.  Here's the original, unmodified code from the original form processor for custom fields:

 

<?php 
$postFields["custom_fields"] = array();
  foreach($_POST as $key=>$val) {
	if (strncmp($key, 'custom_field_', strlen('custom_field_')) === 0) {
	$postFields["custom_fields"][substr($key, strlen('custom_field_'), strlen($key)-1)] = $val;
	}
  }
?>

 


2 REPLIES 2
Member

The code you provided here appears to come from one of the files in our PHP Contact Sample Forms package, which uses the cc_class.php library.  This is an older library, and we are working on integrating the current PHP Wrapper Library into the Sample Forms package at this time, and are encouraging developers to use the newer PHP Wrapper Library.

 

Looking at the code for the cc_class.php, however, it appears that the following array structure would be correct:

 

$postFields["custom_fields"] = array{"custom_field_1"  => '', "custom_field_2" => '', ...);

 

I hope this helps you out.

Mark Coleman
Support Engineer

I got it - actually it's:

 

$postFields["custom_fields"] = array(1  => "", 2 => $var, 3 => "", ...);

 

Thanks

Developer Portal

View API documentation, code samples, get your API key.

Visit Page