vtiger Forum Index vtiger
The Honest Open Source CRM
 

Added Custom fields and now its stopped working?
Click here to go to the original topic

 
       vtiger Forum Index -> Web Forms
Previous topic :: Next topic  
Author Message
jshayler



Joined: 03 Jul 2007
Posts: 77

Posted: Thu Jan 03, 2008 6:18 pm    Post subject: Added Custom fields and now its stopped working?  

Hi All,

I have set up the web forms, and had them working, using only the standard fields that come with it. Everything worked fine until i added some of other fields and a custom field.

I wanted to capture the below fields:-

First Name
Surname
Email Address
Phone Number
Mobile Number
Company
Street Address
City
Post Code
Notes


So i followed the following post:-


http://forums.vtiger.com/viewtopic.php?t=3071

All seemed to have gone ok, but now the leads wont appear in vtiger, i dont get any error message when i submit the lead via the web form!

Its really bizare, so i have posted all the files involved below that i have amended, for anyone to have a look at, and hopefully pick up on the problem:-

SENDDATA.PHP

Code: <?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
*
 ********************************************************************************/

include("config.php");
require_once('nusoap/lib/nusoap.php');

$client = new soapclient2($Server_Path."/vtigerservice.php?service=webforms", false,
                                                $proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();

if($_REQUEST['create'] == 'lead')
{
   $firstname = $_POST['firstname'];
   $lastname = $_POST['lastname'];
   $email = $_POST['email'];
   $phone = $_POST['phone'];
   $mobile = $_POST['mobile'];
   $company = $_POST['company'];
   $lane = $_POST['lane'];
   $city = $_POST['city'];
   $code = $_POST['code'];
   $notes = $_POST['leadnotes'];
   //$country = $_POST['country'];
   //$description = "WebForm : ".$_POST['description'];
   
   $params = array(
                  'firstname'=>"$firstname",
                  'lastname' => "$lastname",
                      'email'=>"$email",
                      'phone'=>"$phone",
                      'mobile'=>"$mobile",
                  'company'=>"$company",
                      'lane'=>"$lane",
                  'city'=>"$city",
                  'code'=>"$code",
                  'notes'=>"$notes",
                  'assigned_user_id'=>"$assigned_user_id",                  
                  //'country'=>"$country",
                      //'description'=>"$description",
         );

   if($lastname != '' && $company != '')
   {
      $result = $client->call('create_lead_from_webform', $params, $Server_Path, $Server_Path);
   
      if($result['faultstring'] != '' && is_array($result))
      {
         echo '<br>'.$result['faultstring'];
      }
      else
      {
         //echo '<br><br>'.$result.'<br><br><a href="index.php">Home</a>';  // JS this is the original Line of Code for here
         //echo '<br><br>'.$result.'<br><br><a href="thankyou.php">thankyou</a>';   JS/  added this line so by clicking on the thank you link it took you to the Thankyou.php
         include("thankyou.php"); // JS ADDED  this now takes you straigth to the thankyou.php
      }
   }
   else
   {
      $error_message = "<h3>Surname Name and Premises Name must be entered to create a Lead.</h3>";
      include("index.php");
   }
}
else
{
   include("index.php");
}

?>


WEBFORMS.PHP

Code: <?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
*
 ********************************************************************************/

require_once("config.php");
require_once('include/logging.php');
require_once('include/nusoap/nusoap.php');
require_once('include/database/PearDatabase.php');
require_once('modules/HelpDesk/HelpDesk.php');

$log = &LoggerManager::getLogger('webforms');

//$serializer = new XML_Serializer();
//$NAMESPACE = 'http://www.vtiger.com/vtigercrm/';
$NAMESPACE = 'http://www.crm.power4pubs.co.uk/crm/';
$server = new soap_server;

$server->configureWSDL('vtigersoap');


$server->register(
   'create_lead_from_webform',
   array(
      
      'firstname'=>'xsd:string',
      'lastname'=>'xsd:string',
      'email'=>'xsd:string',
      'phone'=>'xsd:string',
      'mobile'=>'xsd:string',
      'company'=>'xsd:string',
      'lane'=>'xsd:string',
      'city'=>'xsd:string',
      'code'=>'xsd:string',
      'notes'=>'xsd:string',
      'assigned_user_id'=>'xsd:string'
      //'country'=>'xsd:string',
      //'description'=>'xsd:string',
        ),
   array('return'=>'xsd:string'),
   $NAMESPACE);

$server->register(
   'create_contact_from_webform',
   array(
      'first_name'=>'xsd:string',
      'last_name'=>'xsd:string',
      'email_address'=>'xsd:string',
      'home_phone'=>'xsd:string',
      'department'=>'xsd:string',
      'description'=>'xsd:string',
      'assigned_user_id'=>'xsd:string'
        ),
   array('return'=>'xsd:string'),
   $NAMESPACE);

$server->register(
   'unsubscribe_email',
   array(
      'email_address'=>'xsd:string'
        ),
   array('return'=>'xsd:string'),
   $NAMESPACE);


/**   function used to create lead from webform from the passed details
 *   @param string $lastname   - last name of the lead
 *   @param string $email - email of the lead
 *   @param string $phone - phone number of the lead
 *   @param string $company - company name of the lead
 *   @param string $country - country name of the lead
 *   @param string $description - description to create a lead
 *   @param int $assigned_user_id - assigned to user for the lead
 *   return message success or failure about the lead creation
 */
function create_lead_from_webform($firstname, $lastname, $email, $phone, $mobile, $company, $lane, $city, $code, $notes, $assigned_user_id,)
//$country,   $description,
{
   global $adb;
   $adb->println("Create New Lead from Web Form - Starts");

   if($assigned_user_id == '')
   {
      //if the user id is empty then assign it to the admin user
      $assigned_user_id = $adb->query_result($adb->query("select id from vtiger_users where user_name='admin'"),0,'id');
   }

   require_once("modules/Leads/Leads.php");
   $focus = new Leads();
   $focus->column_fields['firstname'] = $firstname;
   $focus->column_fields['lastname'] = $lastname;
   $focus->column_fields['email'] = $email;
   $focus->column_fields['phone'] = $phone;
   $focus->column_fields['mobile'] = $mobile;
   $focus->column_fields['company'] = $company;
   //$focus->column_fields['country'] = $country;
   //$focus->column_fields['description'] = $description;
   $focus->column_fields['lane'] = $lane;
   $focus->column_fields['city'] = $city;
   $focus->column_fields['code'] = $code;
   $focus->column_fields['cf_495'] = $notes;
   $focus->column_fields['assigned_user_id'] = $assigned_user_id;
   
   $focus->save("Leads");
   //$focus->retrieve_entity_info($focus->id,"Leads");

   $adb->println("Create New Lead from Web Form - Ends");

   if($focus->id != '')
      $msg = 'Thank you for your request, your deatils have now been passed to a Power 4 Pubs representative who will search the market for you.';
   else
      $msg = "Requested failed. Please try again";

   return $msg;
}

/**   function used to create contact from webform from the passed details
 *   @param string $first_name   - first name to create contact
 *   @param string $last_name   - last name to create contact
 *   @param string $email_address - email address to create contact
 *   @param string $home_phone - phone number of home to create contact
 *   @param string $department - department to create contact
 *   @param string $description - description to create contact
 *   @param int $assigned_user_id - assigned to user for the contact
 *   return message success or failure about the contact creation
 */
function create_contact_from_webform($first_name, $last_name, $email_address, $home_phone, $department,$description, $assigned_user_id)
{
   global $adb;

   $adb->println("Create New Contact from Web Form - Starts");
   if($assigned_user_id == '')
   {
      //if the user id is empty then assign it to the admin user
      $assigned_user_id = $adb->query_result($adb->query("select id from vtiger_users where user_name='admin'"),0,'id');
   }

   require_once('modules/Contacts/Contacts.php');
   $focus = new Contacts();

   $focus->column_fields['firstname'] = $first_name;
   $focus->column_fields['lastname'] = $last_name;
   $focus->column_fields['email'] = $email_address;
   $focus->column_fields['homephone'] = $home_phone;
   $focus->column_fields['department'] = $department;
   $focus->column_fields['description'] = $description;
   $focus->column_fields['assigned_user_id'] = $assigned_user_id;

   $focus->save("Contacts");
   //$focus->retrieve_entity_info($focus->id,"Contacts");

   $adb->println("Create New Contact from Web Form - Ends");

   if($focus->id != '')
      $msg = 'Thank you for your interest. Information has been successfully added as Contact in vtigerCRM.';
   else
      $msg = "Contact creation failed. Please try again";

   return $msg;
}

/**   function used to unsubscribe the mail
 *   @param string $emailid - email address to unsubscribe
 *   return message about the success or failure status about the unsubscribe
 */
function unsubscribe_email($emailid)
{
   global $adb;
   $adb->println("Enter into the function unsubscribe_email($emailid)");
   
   $contact_res = $adb->query("select emailoptout from vtiger_contactdetails where email=\"$emailid\"");
   $contact_noofrows = $adb->num_rows($contact_res);
   $emailoptout = $adb->query_result($contact_res,0,'emailoptout');

   if($contact_noofrows > 0)
   {
      if($emailoptout != 1)
      {
         $adb->query("update vtiger_contactdetails set emailoptout=1 where email=\"$emailid\"");
         $msg = "You have been unsubscribed.";
      }
      else
      {
         $msg = "You are already unsubscribed.";
      }
   }
   else
   {
      $msg = "There are no record available for this mail address.";
   }

   $adb->println("Exit from the function unsubscribe_email($emailid)");
   return $msg;
}


//$log->fatal("In soap.php");

/* Begin the HTTP listener service and exit. */
$server->service($HTTP_RAW_POST_DATA);

exit();



?>


INDEX.PHP

Code: <?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
*
 ********************************************************************************/


if($error_message != '')
   echo '<h6><font color="purple">'.$error_message.'</font></h6>';

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>

<script language="Javascript">

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function ValidateForm(){
   var str=document.leadform.email.value;
   var lname = document.leadform.lastname.value;
   var company = document.leadform.company.value;   
   
   if(lname.trim() == ''){
                alert("Last name required..");
                return false;
        }else if(company.trim() == ''){
      alert("Company name required .. ");
      return false;
   }

   if((str.lastIndexOf(".") > 2) && (str.indexOf("@") > 0) && (str.lastIndexOf(".") > (str.indexOf("@")+1)) || (str==''))
      document.leadform.submit();
   else   
      alert('Invalid Email Id');
 }

</script>

<style>
   h3{margin:0; font-size: 14px;}
   hr{color: #EEE; background-color: #EEE; margin: 0; height:1px; }
   body {
   color: #333333;
   font-size: 11px;
   font-family: verdana, sans-serif;
   background-color: #000000;
}
   table#perfect         { background-color: #F5F5F5; border: 1px solid #CCC;}
   table#perfect caption { color: yellow; font-size: 110%; font-weight: bold;
                           background-color: black; padding: 3px;
                           margin-left: auto; margin-right: auto }
   table#perfect th      { text-align: right; font-weight: bold }
   table#perfect div     { text-align: center; margin-top: 6px }
   table#perfect span    { float: right; font-size: 65% }
   table#perfect a       { color: darkslategray; text-decoration: none }
   input.click           { cursor: pointer }
body,td,th {
   color: #FFFFFF;
}
.style13 {color: #666666; font-size: 24px; }
.style18 {color: #666666; font-size: 18px; }
.style19 {color: #FFFFFF}
.style20 {font-size: 24px}
.style21 {color: #FFFFFF; font-size: large; }
.style22 {color: #FFFFFF; font-size: 24px; }
</style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>


<form name="leadform" method=post action="send_data.php">
<p align="center">
  <input type="hidden" name="create" value="lead">
  <img src="Power4Pubs.jpg" width="150" height="60"></p>
<p>&nbsp;</p>
<table width="64%" align="center">
<tr>
      <td width="50%" align="left"><h1>Quotation Request</h1></td>
      <td width="50%">&nbsp;</td>
   </tr>
</table>

<table width="64%" border="0" align="center" cellpadding="5" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FF0000" id="perfect">
   <tr><th width="15%" height="47" bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">First  Name:<sup>*</sup></span></h2></th>
      <td width="32%" bgcolor="#000000"><input type=text name=lastname size=30 value="<?php echo $_POST['firstname']?>"></td>
     <th width="23%" bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Surname Name:<sup>*</sup> </span></h2></th>
     <td width="30%" bgcolor="#000000"><input type=text name=lastname2 size=30 value="<?php echo $_POST['lastname']?>"></td>
   </tr>
      <tr><th bgcolor="#000000" class="style13"><h2><span class="style22"> E-Mail Address:</span></h2></th>
         <td bgcolor="#000000"><input type=text name=email size=30 value="<?php echo $_POST['email']?>"></td>
        <th bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Telephone Number<sup>:*</sup></span></h2></th>
        <td bgcolor="#000000"><input type=text name=phone2 size=30 value="<?php echo $_POST['phone']?>"></td>
      </tr>
      <tr><th bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Mobile Number:</span></h2></th>
         <td bgcolor="#000000"><input name=phone type=text value="<?php echo $_POST['mobile']?>" size=30></td>
        <th bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Premises/Company Name:<sup>*</sup> </span></h2></th>
        <td bgcolor="#000000"><input type=text name=company size=30 value="<?php echo $_POST['company']?>"></td>
      </tr>
      <tr><th bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Street:</span></h2></th>
         <td bgcolor="#000000"><input name=country3 type=text value="<?php echo $_POST['lane']?>" size=30></td>
        <th bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Town / City:</span></h2></th>
        <td bgcolor="#000000"><input type=text name=phone4 size=30 value="<?php echo $_POST['city']?>"></td>
      </tr>
      <tr><th bgcolor="#000000" class="style13"><h2 class="style19"><span class="style20">Postal Code:</span></h2></th>
         <td bgcolor="#000000"><input name=country type=text value="<?php echo $_POST['code']?>" size=30></td>
        <th bgcolor="#000000"><h2>&nbsp;</h2></th>
        <td bgcolor="#000000" class="style18"><h4 class="style19">* These fields must be filled in</h4></td>
      </tr>
   <tr bgcolor="#999999">
     <td height="32" colspan="4" align="center" bgcolor="#000000"><h6 class="style21">Additional Information</h6></td>
   </tr>
   <tr bgcolor="#999999">
     <td colspan="4" align="center" bgcolor="#000000" class="style21">Please use the box below to provide us with as much additioanl information has possible, please include your current Electricity/Gas supplier(s) and account numbers if known.</td>
   </tr>
   <tr bgcolor="#999999">
     <td colspan="4" align="center" bgcolor="#000000"><textarea name=description rows=5 cols=80><?php echo $_POST['notes']?></textarea></td>
   </tr>
   <tr bgcolor="#999999">
     <td colspan="4" align="center" bgcolor="#000000"><input name="Submit" type="button" class=click  onClick="ValidateForm();" value="Submit"></td>
   </tr>
  </table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>


I took the field names straight from the vtiger fields table so i dont understand whats gone wrong?

Is this due to my lack of PHP understanding, which has led to a mistake in one of the files?

Any help or ideas would be great!

Cheers

J
Back to top  
ClearlyTechnical



Joined: 10 Apr 2008
Posts: 13

Posted: Sat Apr 12, 2008 9:43 pm    Post subject: Added Custom fields and now its stopped working?  

I followed the instructions and it worked fine. I would take the original files, put them back, then try to just add one field. Then grow from there.
Back to top  
 
       vtiger Forum Index -> Web Forms
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.15 © 2001, 2002 phpBB Group