hi
thanks for all your responses. ive managed to get the snippet to work, but the only problem is that the redirect isnt working, although my custom snippet returns true as the last line in the snippet. not too sure why it doesnt re direct. my formit code is?
[[!FormIt?
&hooks=`hook.RampartFormit,spam,email,FormSave,redirect,sendToZoho`
&emailTpl=`send-foot-email`
&emailTo=`
[email protected]`
&redirectTo=`8`
&submitVar=`sendfooter`
&validate=`fullname:required,
Email:email:required,
nospam:blank,
Phone:required`
]]
the hook sendToZoho has the following php code in:
<?php
$valid = array();
$modx = new modX();
$arr = $modx->sanitize($_POST);
array_pop($arr);
$newarray = array();
$newarray[] = '<Leads><row no="1"><FL val="Lead Source">Web</FL>';
foreach ($arr as $k=>$v) {
if($k == 'Email') {
// checks email
$email = $v;
$regex = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$^";
if (preg_match($regex, $email))
{
$valid['Email'] = true;
} else {
$valid['Email'] = false;
}
}
if($k == 'LEADCF13') {
// checks message
if(preg_match('/^[a-zA-Z0-9 .\-]+$/i', $v)) {
$valid['message'] = true;
} else {
$valid['message'] = false;
}
}
if($k == 'Phone') {
$phone = $v;
$input = str_replace(' ', '', $phone);
if($input && strlen($input) > 9) {
$pattern = "^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{5}\)?[\s-]?\d{4,5}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$^";
$match = preg_match($pattern,$input);
if ($match != false) {
// We have a valid phone number
$v = $input;
$valid['Phone'] = true;
} else {
// We have an invalid phone number
$valid['Phone'] = false;
}
} else {
$valid['Phone'] = false;
}
}
if($k == 'fullname') {
$names = explode(' ', $v);
if(isset($names[0])) {
$newarray[] = "<FL val='First Name'>{$names[0]}</FL>";
}
if(isset($names[1])) {
$newarray[] = "<FL val='Last Name'>{$names[1]}</FL>";
}
continue;
}
$newarray[] = "<FL val='$k'>$v</FL>";
}
$newarray[] = '</row></Leads>';
$data = str_replace(',','',implode(',', $newarray));
if(!in_array(false, $valid)) {
try {
//Initialize connection
$ch = curl_init('https://crm.zoho.com/crm/private/xml/Leads/insertRecords?');
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, 1);//Regular post
//Set post fields
//this script is being proccessed by a form so I also put all of my $_POST['name'] variable here to be
//used in the $xmlData variable below
$authtoken = "THIS_IS_MY_TOKEN_RECEIVED_FROM_THIRD_PARTY";
$query = "newFormat=1&authtoken={$authtoken}&scope=crmapi&xmlData={$data}";
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);// Set the request as a POST FIELD for curl.
//Execute cUrl session
$result = curl_exec($ch);
throw new Exception('zoho crm export : '.$result);
curl_close($ch);
} catch(Exception $e) {
$modx->log(xPDO::LOG_LEVEL_ERROR,$e);
}
}
return true;
ok, so the email gets generated, the FormSave saves the data to the modx database correctly, and the xml is sent to the zoho crm system. everything works fine, except for the blank screen and no redirect.
cheers