
Originally Posted by
cehrenthal we aretrying to get forms for online lead capture up and running, but struggle to do so. The SugarCRM 4.5e Open Source Edition is running on a Windows 2003 box.
The form is pointed at the right file, and we checked the username, hash and random key several times. still, on submit, we get a blank page. additionally, nothing is captured. we've been through the installation instructions and the wiki and done everything that's there, but still nothing.
Maybe these my samples help you out a little. This is a bit complicated, because mine haas some code checks. This on is form the web form. Note that functions checkMail and checkData can be removed, but i included those here to show that form text can be validated thus you get (at least more) valid data to your Sugar. The more interesting part would be from <form> and downwards.
Code:
<script>
<!--
function checkMail(mail)
{
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(mail)) return true;
else return false;
}
function addToDescription(form, media, address, code, zip){
form.description.value = "this is a sample text that will be added to lead's description field: The message contains following variables:
\n media: " + media +
"\n address: " + address +
"\n code: " + code +
"\n zip: " + zip
}
function check_data(form) {
if(document.leadcap.optionlist.options[document.leadcap.optionlist.selectedIndex].text=="option1")
{
if (document.leadcap.email1.value!="" && !checkMail(document.leadcap.email1.value)) {
alert('email not valid!.');
return false;
}
var required = {
'first_name': 'first name',
'last_name': 'last name',
'account_name': 'account_name',
'primary_address_street': 'street',
'primary_address_city': 'city',
'primary_address_postalcode': 'zip',
'phone_mobile': 'mobile'
};
}
else
{
if (!checkMail(document.leadcap.email1.value)) {
alert('Email not valid!');
return false;
}
else {
var required = {
'first_name': 'name',
'last_name': 'last name',
'primary_address_street': 'Taloyhtiön osoite',
'primary_address_city': 'Kaupunki',
'primary_address_postalcode': 'Postiosoite'
};
}
}
var missing = [];
for(var field in required)
if(form[field].value == '')
missing[missing.length] = required[field];
if(missing.length > 0) {
alert('Following fields were not valid::\n' + missing.join('\n'));
return false;
}
return true;
}
-->
</script>
<form name='leadcap' onsubmit= 'addToDescription(document.leadcap, document.leadcap.optionlist.options[document.leadcap.optionlist.selectedIndex].text,
document.leadcap.primary_address_street.value,
document.leadcap.primary_address_city.value,
document.leadcap.primary_address_postalcode.value);'
action = 'http://your.sugarcrm.com/leadCapture.php' method='post'>
<input type='hidden' name='lead_source' value='Web Site'>
<input type='hidden' name='user' value='Sugar user name'>
<input type='hidden' name='description' value=''>
<input type='hidden' name='redirect' value='http://www.sample.com/'>
<table border=0><tr><td>
<tr><td><font color=red>*</font>first name:</td><td><input type='text' size='50' name='first_name'></td></tr>
<tr><td><font color=red>*</font>last name:</td><td><input type='text' size='50' name='last_name'></td></tr>
<tr><td>email:</td><td><input type='text' size='50' name='email1'></td></tr>
<tr><td>mobile:</td><td><input type='text' size='50' name='phone_mobile'></td></tr>
<tr><td><font color=red>*</font>address:</td><td><input size='50' type='text' name='primary_address_street'></td></tr>
<tr><td><font color=red>*</font>zip code:</td><td><input type='text' size='50' name='primary_address_postalcode'></td></tr>
<tr><td><font color=red>*</font>city:</td><td><input size='50' type='text' name='primary_address_city'></td></tr>
<tr><td>optionlist:</td><td><select name='contact'>
<option value='option1' selected="selected"> option1</option>
<option value='option2'> option2</option>
</select></td></tr>
<tr><td><input type='Submit' name='submit' value='submit' onclick= 'return check_data(this.form);' ></td></tr></table>
</form> This is my leadCapture. It also sends an email. I've edited the code very much here, so forgive me possible errors or inconsictence. This would give some idea how things can be done.
Code:
/**
* To make your changes upgrade safe create a file called leadCapture_override.php and place the changes there
*/
$users = array(
'user' => array('name'=>'user, 'pass'=>'hashcode be sure this really is HASH and not passwd'),
);
if(file_exists('leadCapture_override.php')){
include('leadCapture_override.php');
}
if (!empty($_POST['user']) && !empty($users[$_POST['user']])) {
$current_user->user_name = $users[$_POST['user']]['name'];
if($current_user->authenticate_user($users[$_POST['user']]['pass'])){
$userid = $current_user->retrieve_user_id($users[$_REQUEST['user']]['name']);
$current_user->retrieve($userid);
$leadForm = new LeadFormBase();
$prefix = '';
if(!empty($_POST['prefix'])){
$prefix = $_POST['prefix'];
}
if( !isset($_POST['assigned_user_id']) || !empty($_POST['assigned_user_id']) ){
$_POST['prefix'] = $userid;
}
$_POST['record'] ='';
if( isset($_POST['_splitName']) ) {
$name = explode(' ',$_POST['name']);
if(sizeof($name) == 1) {
$_POST['first_name'] = ''; $_POST['last_name'] = $name[0];
}
else {
$_POST['first_name'] = $name[0]; $_POST['last_name'] = $name[1];
}
}
$return_val = $leadForm->handleSave($prefix, false, true);
/********************
start: Send Email
************************************/
$now=date("d.m.Y H:i", time());
$var1= $_POST['first_name'];
$var2= $_POST['last_name'];
$var3 = $_POST['optionlist'];
$var4= $_POST['contact'];
$var5= $_POST['account_name'];
$var6 = $_POST['primary_address_street'];
$var7= $_POST['primary_address_city'];
$var8= $_POST['primary_address_postalcode'];
mail ("something@some.com",
"$var1 $var2 has contacted you from web ",
--------------------------------------------------
\r\n$var 1$var2 has been added to Sugar as a Lead (you can use all vars here to specify the email more detailed)
\r\n addiotional $var3 data can be added $var4 here also.
\r ","FROM: name <sugarcrm@sugar.com>");
/************************************
*
* End: Send Email
*
************************************/
if(isset($_POST['redirect']) && !empty($_POST['redirect'])){
header("Location: ".$_POST['redirect']);
echo '<html><head><title>CRM</title></head><body>';
echo '<form name="redirect" action="' .$_POST['redirect']. '" method="POST">';
foreach($_POST as $param => $value) {
if($param != 'redirect') {
echo '<input type="hidden" name="'.$param.'" value="'.$value.'">';
}
}
if( ($return_val == '') || ($return_val == 0) || ($return_val < 0) ) {
echo '<input type="hidden" name="error" value="1">';
}
echo '</form><script language="javascript" type="text/javascript">document.redirect.submit();</script>';
echo '</body></html>';
}
else{
echo "Thanks for contacting.";
}
sugar_cleanup();
// die to keep code from running into redirect case below
die();
}
}
echo "We're sorry, the database wasn't available at the mo.";
if (!empty($_POST['redirect'])) {
echo '<html><head><title>'CRM</title></head><body>';
echo '<form name="redirect" action="' .$_POST['redirect']. '" method="POST">';
echo '<html><head><title>ERROR</title></head><body>';
echo '<form name="redirect" action="' .$_POST['redirect']. '" method="POST">';
echo '</form><script language="javascript" type="text/javascript">document.redirect.submit();</script>';
echo '</body></html>';
Bookmarks