cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with add contact form (olny for some field

Occasional Participant

Problem with add contact form (olny for some field

Hi i use this code:


 


 


 @define('CC_USERNAME','xxxxxx');  // Constant Contact username (API enabled) and need to be changed before using the script


 @define('CC_PASSWORD',xxxxxxxx');   // Constant Concact password (API enabled) and need to be changed before using the script


 @define('CC_APIKEY',xxxxxxxxxxxxx);


 @define('LIST_NAME','Newsletter');


 @define('SITE_HOME','index.php');  // Site home page URL


 @define('OUTPUT_TEMPLATE', '');    // Optional output template to use for customizing standard display


 @define('USE_SSL', false);     // Use SSL connection to access API


 @define('DISPLAY_ERRORS', true);   // Display verbose errors to screen (not recommended in production)


 @define('LOGFILE','ccsub.log');    // Log file to save messages to


 @define('LOG_LEVEL', 1);     // level of detail to put in logfile (0 = no logging, 1 = basic info, 2 = debug info)


 @define('CUSTOM_FIELD_PREFIX', 'custom_field_');


 


 


 require "Contact.php";


 


 session_start();


 //$required_params = $_REQUEST;


 $errmsg = '';


 //$required_fields = explode(',', $required_params);


// foreach($required_fields as $field) {


  //if (empty($_POST)) {


 //  // field doesn't exist or is empty - add error message


  // $errmsg .= '<br />Missing field: ' . (substr($field, 0, 6) == 'Custom' ? $_POST : $field);


   echo $errmsg;


  //}


 //}


 


 


  


 $ct = new Contact(CC_USERNAME,CC_PASSWORD,CC_APIKEY,LOGFILE);


 $email = $emailCom;


 $list_name = urlencode(strip_tags($_REQUEST));


 $first_name = urlencode(strip_tags($_REQUEST));


 $last_name= urlencode(strip_tags($_REQUEST));


 $middle_name= urlencode(strip_tags($_REQUEST));


 $company_name = $aziendaCom;

 $city_name = $statoCom;

 $home_number = $telefonocom;


 $job_title= urlencode(strip_tags($_REQUEST));


 if(LIST_NAME != '') $list_name = urlencode(LIST_NAME);


 $cf_array = array();


 foreach($_POST as $k=>$v) {


  if (strncmp($k, CUSTOM_FIELD_PREFIX, strlen(CUSTOM_FIELD_PREFIX)) === 0) {


   $cf_array = $_REQUEST;


  }


 }


 


 $ct->SetPrimaryInfo($email, $list_name, $first_name, $last_name, $middle_name, $company_name, $job_title,$home_number, $city_name);


 $ct->SetCustomFields($cf_array);


 $entry = $ct->MaketEntry();


 $errmsg .= $ct->GetErrorMessage();


 


 //proceed if there are no errors


 //print($errmsg);


 if (empty($errmsg)) {


   $output='';


   if (LOGFILE && LOG_LEVEL == 2) error_log(date('Y-m-d H:i:s') .


         ' Request data: ' . $entry .


         "\n", 3, LOGFILE);


 


   //$list_resp = $ct->FindContactList("Friends"); 


    $request =  "https://api.constantcontact.com/ws/customers/".CC_USERNAME."/contacts";


       $session = curl_init($request);


       // Set up Digest authentication - username and password.


       $userNamePassword = CC_APIKEY."%".CC_USERNAME.":".CC_PASSWORD;


       curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);


       curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);


       curl_setopt($session, CURLOPT_FOLLOWLOCATION  ,1);


       curl_setopt($session, CURLOPT_POST, 1);


       curl_setopt($session, CURLOPT_POSTFIELDS , $entry);


       curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));


       curl_setopt($session, CURLOPT_HEADER, 0);   // Do not return headers


       curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);


       $response = curl_exec($session);


       curl_close($session);


       if (!$response) {


         // curl failed, create error message


    $output .= "


     <h1>Error Encountered!</h1>


     <p>There was an error trying to connect to the server. <br />


     Please go <strong><a href=\"#\" onClick=\"history.go(-1)\">BACK</a></strong> and try again later.</p>


     ";


 


     // write error to logfile


     if (LOGFILE && LOG_LEVEL) error_log(date('Y-m-d H:i:s') .


          ' Error attempting to connect via curl to ' . $request .


          "\n", 3, LOGFILE);


 


 


all fiilds are populated correctly expetc these one:


 


$city_name = $statoCom;

 $home_number = $telefonocom;


$statoCom and  $telefonocom contain correct value


 


Any suggestion?


This name are correct?


 $city_name 


 $home_number


 


Thanks

7 REPLIES 7
Highlighted
CTCT Employee

This is our old sample script

This is our old sample script that you are using. After looking into the two required files (AddAContact.php and Contact.php) it appears as though a collection of information including City and Home Phone are supposed to be submitted using a function that is never called in the script. I am working on correcting this and I will post a reply with the updated code shortly.

Dan H

Support Engineer, Constant Contact

Highlighted
Occasional Participant

Thanks

OK thanks ii am waiting your code


Thanks for the support

Highlighted
CTCT Employee

As I mention before this is

As I mention before this is our old sample script and I was surprised to see that there was a large area of code that was not working at all.


 


I have a resolution with only a few code changes outlined below:


 


In the Contact.php page, locate the SetContactInfo function and change it to the following:


 


    public function SetContactInfo($home_num, $work_num, $addr_1, $addr_2, $addr_3, $city, $state, $country, $postal_code, $sub_postal) {

        $this->home_number=$home_num;

        $this->work_number=$work_num;

        $this->address_line_1=$addr_1;

        $this->address_line_2=$addr_2;

        $this->address_line_3=$addr_3;

        $this->city_name=$city;

        $this->state_code=$state;

        $this->country_code=$country;

        $this->zip_code=$postal_code;

        $this->sub_zip_code=$sub_postal;

    }


This function will now process the remaining contact details including the city and phone numbers.


 


Next you will want to locate the section in the AddAContact.php file that contains the declarations of the contact details. It begins with the following code:


 $ct = new Contact(CC_USERNAME,CC_PASSWORD,CC_APIKEY,LOGFILE);

 $email = $emailCom;

 $list_name = urlencode(strip_tags($_REQUEST));


  ...


and add the following code:


 


    $home_num= urlencode(strip_tags($_REQUEST));

    $work_num= urlencode(strip_tags($_REQUEST));

    $addr_1= urlencode(strip_tags($_REQUEST));

    $addr_2= urlencode(strip_tags($_REQUEST));

    $addr_3= urlencode(strip_tags($_REQUEST));

    $city= urlencode(strip_tags($_REQUEST));

    $state= urlencode(strip_tags($_REQUEST));

    $country= urlencode(strip_tags($_REQUEST));

    $postal_code= urlencode(strip_tags($_REQUEST));

    $sub_postal= urlencode(strip_tags($_REQUEST));


 


This will now look for the preceding fields being submited from the form. Notice that is contains the city and home_num fields.


 


Next look slightly lower in the code and locate the following line:


$ct->SetPrimaryInfo($email, $list_name, $first_name, $last_name, $middle_name, $company_name, $job_title);


Now add the following call directly below that:


$ct->SetContactInfo($home_num, $work_num, $addr_1, $addr_2, $addr_3, $city, $state, $country, $postal_code, $sub_postal);


 


Finally you will need to add the desired fields to the form that you are using to request the data. For instance, the Home Phone Number field would look like so:


<input type="text" name="home_num" maxLength="100" />


 


This is using the names that are described in the REQUEST variables:


$home_num= urlencode(strip_tags($_REQUEST));


I hope this helps you out. This sample was seriously lacking functionality due to a few big chunks of missing code.


 


Best of luck.

Dan H

Support Engineer, Constant Contact

Highlighted
Occasional Participant

Thanks all fine except for one field (home num)

how i can attach you files so you can see it?

Highlighted
CTCT Employee

Please attach your code in an

Please attach your code in an email to Web services.

Dan H

Support Engineer, Constant Contact

Highlighted
Occasional Participant

Done mail sent

thanks

Highlighted
CTCT Employee

I will be taking a look at

I will be taking a look at the code shortly and replying to your email.

Dan H

Support Engineer, Constant Contact