3

I'm using Podio's podio-php for their API for saving data from a form to Podio, and haven't had any issues except this small but annoying one. When I use the $visit_arr-array, the fields in Podio are blank, but when I use the manually created array, $visit_array_with_manual_values, it works fine. When I print the arrays (print_r), they are identical. I don't know much about Objects in PHP, but can the array_push-function somehow make the $visit_arr-array less valid for this procedure? Or is the problem somewhere else? Thx.

// create array
$visit_arr = array();

// loop through visit items from form
$i = 0;
while ( $i < $num_visit_items ) {
    $j = $i + 1;
    if ( isset( $_POST['visit'.$j.''] ) ) {
        array_push($visit_arr, $_POST['visit'.$j.'']);
    }
    $i++;
}

// alternative array (which works)
$visit_array_with_manual_values = array(123,456,789);

// create item in Podio
$fields = new PodioItemFieldCollection(array(
  new PodioTextItemField(array(
    "external_id" => "titel",
    "values" => $firstname
  )),
  new PodioTextItemField(array(
    "external_id" => "lastname",
    "values" => $lastname
  )),
  new PodioAppItemField(array(
    "external_id" => "visit",
    "values" => $visit_arr
  )),
  new PodioTextItemField(array(
    "external_id" => "description",
    "values" => $description
  ))
));
  • Are you sure that the `$_POST` variables you are trying to reference exist? Multiple values sent by form can be interpreted as an array if set up right - see [here](http://stackoverflow.com/questions/20184670/html-php-form-input-as-array). Your code (if these post values don't exist) will transparently pass an empty array as the values of the PodioAppItemField, where it would be more obvious if an error occurred (HTTP status code 400 Bad Request maybe) if any field was missing. – Benjamin Aug 03 '15 at 16:22

0 Answers0