The following code was written for the following conditions:
1. MachForm version 2.4
2. The "Redirected URL" already has some parameters. For example, http://xx.xx.xx.xx/process_form_data.php?form_name=template&itemcode=123432
To send the form data to a php program, replace the line
$commit_result['form_redirect'] = $form_redirect;
in includes/post-functions.php with the following code (probably should be a function instead):
$url_data = '';
$entry_details = get_entry_details($form_id,$new_record_id,'');
foreach ($entry_details as $data) {
if ($data['element_type'] == 'textarea') {
$data['value'] = nl2br($data['value']); //add br before newline
$data['value'] = str_replace("\r\n", '', $data['value']); //remove newline because it breaks php
}
elseif ($data['element_type'] == 'file') {
$data['value'] = strip_tags($data['value'], '<a>'); //remove the image tag, but keep href
}
elseif ($data['element_type'] == 'checkbox') {
$data['value'] = strip_tags($data['value'], '<br>'); //remove the image tag, but keep <br>
$data['value'] = str_replace('', ',', $data['value']); //replace <br> with ','
$data['value'] = preg_replace ('/^ /', '', $data['value']); //remove the beginning space
$data['value'] = preg_replace ('/,$/', '', $data['value']); //remove the trailing ','
}
elseif ($data['element_type'] == 'phone') {
$data['value'] = str_replace(' ', '', $data['value']); //remove spaces
}
elseif ($data['element_type'] == 'address') {
$data['value'] = str_replace('', ', ', $data['value']); //prefer ',' over <br>
}
//target php program fails to get some data values correctly due to existence of non-alphanumeric characters
$data['value'] = urlencode($data['value']);
//replace ' ' with nothing, because empty fields have ' ' after using urlencode() previously
$data['value'] = str_replace('%26nbsp%3B', '', $data['value']);
$url_data .= $data['label'] . '=' . '"' . $data['value'] . '"' . '&';
//fwrite ($mlog, $url_data . "\n"); //for testing only
}
$commit_result['form_redirect'] = $form_redirect . '&' . $url_data; 