0

I use GravityForms in my WordPress site, and have the GravityForms to Salesforce API plugin that adds people who fill out a form as leads in Salesforce. It works fine, except for when people don't enter a company name. Is there a way to have it default to their full name if they don't enter a company?

Here's my code. I added alert boxes to help debug, but they don't even run!

add_filter('gform_after_submission_1', 'create_company_full_name', 10, 4); 
function create_company_full_name($entry, $form){ 
    $field_we_are_checking = '77'; 
    $name = $entry['1.3'].' '.$entry['1.4']; 

    if(empty($entry[$field_we_are_checking])){ 
        $entry[$field_we_are_checking] = $name; 
    } 
    return;
} 

http://www.gravityforms.com/ http://wordpress.org/plugins/gravity-forms-salesforce/

UPDATE: Here's the code that worked in the end:

add_filter('gform_pre_submission_1', 'create_company_full_name', 10, 2);
function create_company_full_name($entry, $form){
    $field_we_are_checking = 'input_77';
    $name = $_POST['input_3'].' '.$_POST['input_4'];
    if(empty($_POST[$field_we_are_checking])){
        $_POST[$field_we_are_checking] = $name;
    }
    return;
}

where 1 (from gform_pre_submission_1) is the id of the form and input_77, input_3, and input_4 refer to the IDs of the fields in question (company, first name, last name)

closed as off-topic by Pieter Goosen, Nicolai, birgire, Johannes Pille, fuxia Sep 1 '14 at 21:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Pieter Goosen, Nicolai, birgire, Johannes Pille, fuxia
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    You will get better response if you link to relevant resources, like the source code for the plugins in question. – s_ha_dum Aug 12 '13 at 13:47
0

First thought is - why not make Company be required?

If that's not acceptable, there should be a way. I've not used this API, but have used other Gravity Forms hooks. Assuming you can hook in before it talks to the API, you should be able to check for the absence of one field, and replace it's value with that of another.

Example... bear in mind this is taken from another API for Gravity Forms.

add_filter('gform_pre_submission_1', 'user3515_function');
function user3515_function($form){
    $field_we_are_checking = 'input_77';
    $name = $_POST['input_3'].' '.$entry['input_4'];

    if(empty($_POST[$field_we_are_checking])){
        $_POST[$field_we_are_checking] = $name;
    }
    return;
}

EDITED

You'll obviously want to utilize the correct hook for your filter. gform_pre_submission should be good, you'll have to test. You'll also need to supply the correct field names for company and name. You can learn those by looking at a completed result in phpmyadmin under gforms... lead detail I believe. Otherwise inspect in Chrome and it should tell you what field numbers each is.

Good luck, let me know if this gets you in the right direction.

  • I thought about making company be required, but for many people it wouldn't apply. – user3515 Aug 12 '13 at 14:22
  • I think this is the right direction, but you totally lost me. From what I understand: I need to add a custom function that will run when they submit the form, that will check if company is blank, and if so, fill it with the first and last name. My questions: 1) Where do I put that PHP code? 2) How do I know which hook to apply it to? 3) Can I get the field numbers straight from gravityform's gui? THANKS! – user3515 Aug 12 '13 at 14:25
  • Put it in your themes functions.php file, for example. This is probably the best hook as it hopefully runs before your third party plugin / add-on. gravityhelp.com/documentation/page/Gform_after_submission -- i already told you how to learn the form ids. Just view your html output to see their names. You want the numeric part. – GhostToast Aug 12 '13 at 14:51
  • Let me know if this works for you – GhostToast Aug 13 '13 at 12:04
  • I'm trying it now. Do I need to tell it to only do this if $form is the ID of the correct form? – user3515 Aug 13 '13 at 15:40
0

As far as I've seen last name is the only required field to create a record on the SF side. Could you remove the requirement for the company name on the field on the SF side?

Also you could add some conditional logic on the GF field for company, if the field is blank add the value of another field (create a hidden field with a default value of "unknown" for example) and send that value into SF.

  • Our salesforce is set up to require a company, I don't remember why. When people don't have a company, we just give it their full name. – user3515 Aug 14 '13 at 13:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.