Results 1 to 7 of 7

Thread: Online Leadcapture

  1. #1
    cehrenthal is offline Member
    Join Date
    Sep 2006
    Posts
    9

    Default Online Leadcapture

    Hi,

    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.

    Any help would be greatly appreciated!

    Thanks, Christian

  2. #2
    ttlinna is offline Sugar Community Member
    Join Date
    Oct 2005
    Posts
    66

    Default Re: Online Leadcapture

    Quote 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>';

  3. #3
    czei is offline Sugar Community Member
    Join Date
    Sep 2006
    Posts
    44

    Default Re: Online Leadcapture

    Thank you for replying and for posting example code, but are you implying it won't just work out of the box? I'm having exactly the same problem as the original poster. I simply edited leadCapture_override.php as per instructions to had the right username and hash, and the resulting pages are just blank, and no errors are generated in sugarcrm.log.

    I've been working on this for months, and haven't gotten anywhere with it :-(

  4. #4
    seanwhe is offline Junior Member
    Join Date
    Sep 2007
    Posts
    1

    Default Re: Online Leadcapture

    Hi,

    I've use the Lead Generation Form feature of Sugar to create forms. It works well with one problem. When I specify a redirect URL it captures the user input correctly but then redirects to something non-existent.

    On examination I found that prior to any user submit the value of redirect is the correct fully qualified url and path to content, but after the fully qualified url is removed from the form source and all the remians is the relative path to the content.

    So at start the form contains:

    <tr>
    <td style="display: none;"><input type="hidden" value="http://www.stockinvestornetwork.co.za/content/view/1853/50/" name="redirect_url" id="redirect_url" /></td>
    </tr>

    After submit it contains

    <tr>
    <td style="display: none;"><input type="hidden" value="content/view/1853/50/" name="redirect_url" id="redirect_url" /></td>
    </tr>

    The page is redirected in both cases to

    http://www.stockinvestornetwork.co.za/crm/content/view/1853/50/

    Which is not a valid content item.

    Does anyone know why this happens and can give a hint as to how I can prevent this happening?

  5. #5
    lopes80andre is offline Sugar Community Member
    Join Date
    Mar 2008
    Posts
    31

    Default Re: Online Leadcapture

    Quote Originally Posted by ttlinna
    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>';
    Hi,

    This will work with SugarCE5.0?

    I want to add an lead entry to my website, but I can't find information on how to do it. There are information on how to do this in SugarCE 5.0?

    Can I made an PHP scrit to send directly to SugarCRM database?


    Best Regards, André.
    Last edited by lopes80andre; 2008-03-02 at 09:17 PM.

  6. #6
    vyoumans is offline Member
    Join Date
    Jul 2008
    Posts
    10

    Default Re: Online Leadcapture

    WOW--- I am glad I am not the only one that can not get this work... I am having the exact same problem using sugar v5 - community edition. NO JOY at all... I have followed the Wiki Instructions for days now... and nothing.
    I have also been hacking the leadCapture.php file. and I think my problem may be the credentials that I am sending it.

    I would really like to get a details explanation of what goes where in terms of passing parameters...
    let me try to start:

    IN THE leadCapture_override.php file...

    $users = array(
    'web Site' => array( 'name' => 'admin', 'pass' => 'f4gfashmhgjhgj7abe4febe9cb880' ));
    ?>

    $users = array(
    'param1' => array( 'name' => 'param2', 'pass' => 'param3' ));
    ?>
    Param1 is the LEAD SOURCE
    'Web SIte' is a default LEAD SOURCE. I assume that is what this is suppose to be?


    Param2 is a valid and active user name in SugarCRM
    'admin' in this case becuase there is definately an admin user.

    param3
    I cut and pasted teh PW Hash out of the Users Table in the DB.

    so after hacking the leadCapture.php file, I came to the conclusion that the User was crashing the script. So, I am guesing for now that I dont understand the correct way to do the leadCapture_override.php file.

    could I get some commetns here please

  7. #7
    vyoumans is offline Member
    Join Date
    Jul 2008
    Posts
    10

    Default Re: Online Leadcapture

    could someone please post their leadCapture_override.php file, and explain their parameters.... I am thinking that this is where i am stuck

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •