dimanche 19 avril 2015

Create leads from PHP form Email - Odoo - Gravity Forms

I'm creating Leads on Odoo, based on received Emails, these Emails come from a website which has gravityforms plugin forms.


The process is like this:


A client or person, fills a form in the website, this form data is emailed to an Email configured into Odoo, and it converts the incoming messages into leads automatically.


So far it is indeed creating the leads, but of course, these are misconfigured Leads, I'll explain a little bit this point.


These forms are created with gravityforms plugin: GravityForms


This plugin has an API, and there's a function called gform_after_submission Documentation here: gform_after_submission


I'm using a trigger, placed on the current wordpress theme functions.php file, this is the code:



add_action("gform_post_submission", "set_post_content", 10, 2);
function set_post_content($entry, $form){
//Gravity Forms has validated the data
//Our Custom Form Submitted via PHP will go here
// Lets get the IDs of the relevant fields and prepare an email message
$message = print_r($entry, true);
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('kristian.koci@gmail.com, odoo@4geeks.com.ve', 'Getting the Gravity Form Field IDs', $message, array( 'body' => $body ));
}


This works like a charm, I mean, this should send an Email to the receipts I've specify on it, every time a form is submitted into the website.


BUT, the emails come in this format:



[1] => kristian
[2] => gago
[3] => kkoci2000@hotmail.com
[4] => +584162029294
[5] => 04/10/2015
[6] => 60
[7] => 90.000
[8] => Vizcaya - Miami, FL
[12] => The Deering Estate - Cutler Bay, Miami, FL
[13] => The Deering Estate - Cutler Bay, Miami, FL
[11] => Hola


This is the form on the website: contact-us


As you can see, I get the ID's and data on these ID's submitted into the form, but in Odoo's case, I need to format these emails into some labels, like this example:



add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {

$post_url = 'http://thirdparty.com';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar ( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );

}


On this one, it assigns a label to every ID, I have the ID's but I can't figure out how to make this example work with the code I'm currently using, I need to email this with these fields instead of the ID's, so Odoo can read them and create Leads accordingly.


Attached is a still of a Lead created with this format, of course I can't use this like this, I think there is no need to further customization or actions on Odoo's part, I think I need to actually format these emails to obtain the desired results.


I hope I've explained myself.


Any ideas?


Thanks in advance!


ScreenShot Odoo Lead


Aucun commentaire:

Enregistrer un commentaire