Viewing 14 replies - 16 through 29 (of 29 total)
  • Plugin Author Upi

    (@upi)

    Hi
    We’ll be happy to provide a solution. Can you please contact us on
    https://www.upicrm.com/contact ?
    with more details ?
    Thanks
    Uri

    Thread Starter sprocker

    (@sprocker)

    just tried bit got “Failed to send your message. Please try later or contact the administrator by another method.” from the contact form so I sent an email direct to the email at the bottom of your page – I trust you get that one?

    Deb x

    Plugin Author Upi

    (@upi)

    Hi Deb,
    as requested – though little delayed – please see code example and explanation bellow:

    1. Create A function to be called when a lead status changes or when a lead is created. The Function receives the lead ID.
    2. Get all lead details by calling function UpiCRMLeads::get_by_id()
    3. Get all optional headers including all existing fields by calling function
    UpiCRMUIBuilder::get_list_option()
    4. Get contact forms fields mapping to UpiCRM fields by calling function UpiCRMFieldsMapping::get_all_by()
    5. Code example show nested loop that processes the entire received information and can present the information by using function
    UpiCRMUIBuilder::lead_routing()
    Code example:

    function upicrm_hook($lead_id) {
        $UpiCRMLeads = new UpiCRMLeads();
        $UpiCRMUIBuilder = new UpiCRMUIBuilder();
        $UpiCRMFieldsMapping = new UpiCRMFieldsMapping();
    
        $getLeads = $UpiCRMLeads->get_by_id($lead_id); //get lead data
        $listOption = $UpiCRMUIBuilder->get_list_option(); //get UI options & existing fields
        $getNamesMap = $UpiCRMFieldsMapping->get_all_by($getLeads->source_id, $getLeads->source_type); //get lead fields mapping 
    
       foreach ($listOption as $key => $list_option) {
            foreach ($list_option as $key2 => $field_name) {
                $value = $UpiCRMUIBuilder->lead_routing($getLeads, $key, $key2, $getNamesMap, true);
                echo "{$field_name}: {$value}<br />";
            }
    
        }
    }
    add_action( 'upicrm_after_lead_change_status', 'upicrm_hook' );

    Would you need more help / support on this?
    please let us know
    thanks
    Uri

    Plugin Author Upi

    (@upi)

    We’re marking it as “resolved”, if you need more assistance, please let us know!

    Thread Starter sprocker

    (@sprocker)

    Sorry – been away and only just got chance to get back to this….

    OK, so I add this code to my functions.php

    function upicrm_hook($lead_id) {
    $UpiCRMLeads = new UpiCRMLeads();
    $UpiCRMUIBuilder = new UpiCRMUIBuilder();
    $UpiCRMFieldsMapping = new UpiCRMFieldsMapping();
    $getLeads = $UpiCRMLeads->get_by_id($lead_id); //get lead data
    $listOption = $UpiCRMUIBuilder->get_list_option(); //get UI options & existing fields
    $getNamesMap = $UpiCRMFieldsMapping->get_all_by($getLeads->source_id, $getLeads->source_type); //get lead fields mapping

    foreach ($listOption as $key => $list_option) {
    foreach ($list_option as $key2 => $field_name) {
    $value = $UpiCRMUIBuilder->lead_routing($getLeads, $key, $key2, $getNamesMap, true);
    echo “{$field_name}: {$value}
    “;
    }

    }
    }

    How do I then get my values from the posted form into my insert script:

    connect to other db
    INSERT INTO TableName (field1, field2, field3, field4, field4, field6, field7) VALUES (‘$field1’, ‘$field2’, ‘$field3’, ‘$field4’, ‘$field5’, ‘$field6’, ‘$field7’ )”);

    Thanks
    Deb

    Plugin Author Upi

    (@upi)

    Hi,
    we’ll post a code example soon… a day r two… stay tuned ??

    Plugin Author Upi

    (@upi)

    Hi,
    please see code below: this action will occur when a new lead is received .

    function upicrm_hook($lead_id) {
        $UpiCRMLeads = new UpiCRMLeads();
        $UpiCRMUIBuilder = new UpiCRMUIBuilder();
        $UpiCRMFieldsMapping = new UpiCRMFieldsMapping();
        $getLeads = $UpiCRMLeads->get_by_id($lead_id); //get lead data
        $listOption = $UpiCRMUIBuilder->get_list_option(); //get UI options & existing fields
        $getNamesMap = $UpiCRMFieldsMapping->get_all_by($getLeads->source_id, $getLeads->source_type); //get lead fields mapping
    
       $sql_field = "";
       $sql_value = "";
       foreach ($listOption as $key => $list_option) {
            foreach ($list_option as $key2 => $field_name) {
                $value = $UpiCRMUIBuilder->lead_routing($getLeads, $key, $key2, $getNamesMap, true);
                $sql_field.= "<code>{$field_name}</code>,";
                $sql_value.= "'{$value}',";
            }
        }
        $sql_field = rtrim($sql_field, ",");
        $sql_value = rtrim($sql_value, ",");
    
        $query = "INSERT INTO TableName ({$sql_field}) VALUES ({$sql_value})";
        mysql_query($query);
    
    }
    
    add_action( 'upicrm_after_new_lead', 'upicrm_hook' );
    Thread Starter sprocker

    (@sprocker)

    That is great…..but I already have a table with set columns already set up and this can not be changed.

    I have the code for $query = “INSERT INTO TableName ({$sql_field})

    I need to be able to get the each field from the submitted form as a separate variable so I can use it in the correct place in my insert code.

    Foe example, my form has FirstName, Surname, your-email, Phone, your-message, and I want to track the source – I need to set
    $FNAME =
    $LNAME =
    $EMAIL =
    $TELNO =
    $notes =
    $utmSource =

    I can then use this in my insert string and I am done!

    Plugin Author Upi

    (@upi)

    pleas try the following:

    function upicrm_hook($lead_id) {
        $UpiCRMLeads = new UpiCRMLeads();
        $UpiCRMUIBuilder = new UpiCRMUIBuilder();
        $UpiCRMFieldsMapping = new UpiCRMFieldsMapping();
        $getLeads = $UpiCRMLeads->get_by_id($lead_id); //get lead data
        $listOption = $UpiCRMUIBuilder->get_list_option(); //get UI options & existing fields
        $getNamesMap = $UpiCRMFieldsMapping->get_all_by($getLeads->source_id, $getLeads->source_type); //get lead fields mapping
    
       $sql_field = "";
       $sql_value = "";
       foreach ($listOption as $key => $list_option) {
            foreach ($list_option as $key2 => $field_name) {
                $value = $UpiCRMUIBuilder->lead_routing($getLeads, $key, $key2, $getNamesMap, true);
                $arr[$field_name] = $value;
            }
        }
        $query = "INSERT INTO TableName (<code>field1</code>,<code>field2</code>,<code>field3</code>) VALUES ('{$arr['Name']}','{$arr['Last name']}','{$arr['Email']}')";
        mysql_query($query);
    
    }
    
    add_action( 'upicrm_after_new_lead', 'upicrm_hook' );

    works?

    Thread Starter sprocker

    (@sprocker)

    no, did not work, sorry….but I used

    $_POST[‘FirstName’] for my values and that did….how is the UTM posted?

    Thanks

    Plugin Author Upi

    (@upi)

    Can you please post your code and we’ll refer to it ?

    Thread Starter sprocker

    (@sprocker)

    function upicrm_hook($lead_id) {
    $UpiCRMLeads = new UpiCRMLeads();
    $UpiCRMUIBuilder = new UpiCRMUIBuilder();
    $UpiCRMFieldsMapping = new UpiCRMFieldsMapping();
    $getLeads = $UpiCRMLeads->get_by_id($lead_id); //get lead data
    $listOption = $UpiCRMUIBuilder->get_list_option(); //get UI options & existing fields
    $getNamesMap = $UpiCRMFieldsMapping->get_all_by($getLeads->source_id, $getLeads->source_type); //get lead fields mapping

    $sql_field = “”;
    $sql_value = “”;
    foreach ($listOption as $key => $list_option) {
    foreach ($list_option as $key2 => $field_name) {
    $value = $UpiCRMUIBuilder->lead_routing($getLeads, $key, $key2, $getNamesMap, true);
    $sql_field.= “{$field_name},”;
    $sql_value.= “‘{$value}’,”;
    }
    }
    $sql_field = rtrim($sql_field, “,”);
    $sql_value = rtrim($sql_value, “,”);

    foreach ($listOption as $key => $list_option) {
    foreach ($list_option as $key2 => $field_name) {
    $value = $UpiCRMUIBuilder->lead_routing($getLeads, $key, $key2, $getNamesMap, true);
    $arr[$field_name] = $value;
    }
    }

    // $query = “INSERT INTO TableName ({$sql_field}) VALUES ({$sql_value})”;
    // mysql_query($query);

    $FNAME = $_POST[‘FirstName’];
    $LNAME = $_POST[‘Surname’];
    $EMAIL = $_POST[‘your-email’];
    $TELNO = $_POST[‘Phone’];
    $notes = $_POST[‘your-message’];
    $Source = “24”;

    $EnqDate = date(‘Y-m-d H:i:s’);
    $ContactDate = $_POST[‘date-377’];
    $BTTC = $ContactDate . ” at ” . $_POST[‘ContactTime’];

    $con=mysqli_connect(“localhost”,”dbname”,”password”,”dbdetails”);
    // Check connection
    if (mysqli_connect_errno())
    {
    echo “Failed to connect to MySQL: ” . mysqli_connect_error();
    }

    mysqli_query($con,”INSERT INTO dbname.Customers (ID, EnqDate, EnqTime, FNAME, MiddleNames, LNAME, ReportWriter, Adviser, DOB, TELNO, MobileTel, OtherTel, ADD1, ADD2, ADD3, ADD4, ADD5, PCODE, EMAIL) VALUES (NULL, ‘$EnqDate’, NULL, ‘$FNAME’, ‘$MiddleNames’, ‘$LNAME’, NULL, NULL, ‘$DOB’, ‘$TELNO’, ‘$MobileTel’, NULL, ‘$ADD1’, ‘$ADD2’, ‘$ADD3’, ‘$ADD4’, ‘$ADD5’, ‘$PCODE’, ‘$EMAIL’);”);

    mysqli_close($con);

    }

    add_action( ‘upicrm_after_new_lead’, ‘upicrm_hook’ );

    Plugin Author Upi

    (@upi)

    Hi,
    sorry to admit – we’ve looked at your code and couldn’t grasp the logic behind the lines.
    According to our best understanding, these are the only line of code the you need to edit:

    $query = “INSERT INTO TableName (field1,field2,field3) VALUES (‘{$arr[‘Name’]}’,'{$arr[‘Last name’]}’,'{$arr[‘Email’]}’)”;


    Uri

    Thread Starter sprocker

    (@sprocker)

    to put it another way…..

    if I want to find the value of the first name field I used $_POST[‘FirstName’] and it worked fine.

    What would I need to use to find the value of the UTM Source ?

    Thanks

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘Insert enquiry into separate db’ is closed to new replies.