I have a modx revolution snippet [ajax processor actually] that passes some data to another snippet calling a function...
<?php
// processor.formdata
$status = 'success';
$msg = '';
$output = $modx->runSnippet($_POST['snippet'],array(
'function' => $_POST['function'],
'formdata' => $_POST
));
$modx->log(modX::LOG_LEVEL_ERROR,'got updateSurchargeData status. '.$output['status']);
$modx->log(modX::LOG_LEVEL_ERROR,'got updateSurchargeData message. '.$output['msg']);
$response_array = array(
'status' => $output['status'],
'msg' => $output['msg'],
);
header('Content-type: application/json');
$output = json_encode($response_array);
return $output;
The $modx-runSnippet runs this:
<?php
//AmericanSurcharge
//echo $scriptProperties('form');
//$modx->log(modX::LOG_LEVEL_ERROR,'Running snippet. '.$function);
//$modx->log(modX::LOG_LEVEL_ERROR,'Running snippet. '.implode(',',$formdata));
$output = '';
$core = $modx->getOption('core_path').'components/americansurcharge/model/';
$surcharge = $modx->getService('americansurcharge', 'AmericanSurcharge', $core, $scriptProperties);
if (!$surcharge instanceof AmericanSurcharge){
return 'Insantiation failed';
}else{
$scriptProperties['formdata'] = $formdata;
$output = $surcharge->$scriptProperties['function']($scriptProperties);
}
return $output;
which in turn runs this:
/**
*
* update one surcharge data
* AmericaSurcharge.class.php
*
*/
public function updateSurchargeData($scriptProperties){
$this->modx->log(modX::LOG_LEVEL_ERROR,'Running updateSurchargeData. '.implode(',',$scriptProperties['formdata']));
$output = array(
'status' => 'success',
'msg' => 'this is the message to return.',
);
$this->modx->log(modX::LOG_LEVEL_ERROR,'Finished running updateSurchargeData. '.$output['status']);
$this->modx->log(modX::LOG_LEVEL_ERROR,'Finished running updateSurchargeData. '.$output['msg']);
return $output;
}
Everything works & runs successfully, but the returned values from the $output = $modx-runSnippet return both "A" in each array key!
looking at the logs from AmericaSurcharge.class.php I get this:
(ERROR @ /index.php) Finished running updateSurchargeData. success
(ERROR @ /index.php) Finished running updateSurchargeData. this is the message to return.
and immediately following that from processor.formdata:
[2014-07-05 23:10:29] (ERROR @ /index.php) got updateSurchargeData status. A
[2014-07-05 23:10:29] (ERROR @ /index.php) got updateSurchargeData message. A
So somewhere between returning the $ouput array from AmericaSurcharge.class.php and getting it back in processor.formdata, something is happening to the values.
what am I doing wrong?