Skip to content

Commit

Permalink
Merge branch 'feature/prefix-field-names' into 'master'
Browse files Browse the repository at this point in the history
Feature/prefix certain field names

Closes #26 and #29

See merge request products/brilliant-plugins/wordpress-to-lead-for-salesforce-crm!1
  • Loading branch information
nciske committed Jun 1, 2020
2 parents a08feb6 + 82b9c75 commit e75e9a5
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 32 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Formerly known as *WordPress-to-lead for Salesforce CRM*

Brilliant Web-to-Lead for Salesforce creates a solid integration between your WordPress install(s) and your [Salesforce CRM](http://www.salesforce.com) account! People can enter a contact form on your site, and the lead goes straight into Salesforce: no more copy pasting lead info, no more missing leads: each and every one of them is in Salesforce.com for you to follow up.

### Check out the (slightly out of date) screencast
http://www.youtube.com/watch?v=hnMzkxPUIyc

You can fully configure all the different settings for the form, and then use a shortcode to insert the form into your posts or pages, or you can use the widget that comes with the plugin and insert the form into your sidebar!

## More Information ##
Expand Down
70 changes: 62 additions & 8 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
=== Brilliant Web-to-Lead for Salesforce ===
Contributors: brilliantplugins, nickciske, stuporglue, jrfoell
Contributors: brilliantplugins, nickciske
Tags: crm, contact form, contactform, web to lead, case to lead, salesforce.com, salesforce, salesforce crm, contact form plugin, contact form builder
Requires at least: 4.0
Tested up to: 5.1
Stable tag: 2.7.3.4
Requires PHP: 7.2
Tested up to: 5.4.1
Stable tag: 2.7.3.5
License: GPLv2
Donate link: https://donate.charitywater.org/donate

Expand All @@ -13,13 +14,10 @@ Brilliant Web-to-Lead for Salesforce creates a solid integration between your Wo

Brilliant Web-to-Lead for Salesforce creates a solid integration between your WordPress install(s) and your [Salesforce CRM](http://www.salesforce.com) account! People can enter a contact form on your site, and the lead (or case) goes straight into Salesforce CRM: no more copy pasting lead info, no more missing leads: each and every one of them is in Salesforce.com for you to follow up.

### Check out the screencast
[youtube http://www.youtube.com/watch?v=hnMzkxPUIyc]
### Features

You can fully configure all the different settings for the form, and then use a shortcode to insert the form into your posts or pages, or you can use the widget that comes with the plugin and insert the form into your sidebar!

Please see this [Demo video](http://www.youtube.com/watch?v=hnMzkxPUIyc) to get a full grasp of some of the power this plugin holds (though it's a bit outdated!).

#### Previous contributors:
* [Joost de Valk](http://profiles.wordpress.org/joostdevalk/)
* [ModernTribe](http://profiles.wordpress.org/moderntribe/)
Expand Down Expand Up @@ -65,6 +63,7 @@ SalesForce is inconsistent in naming built in fields, and even misreports the na

<strong>Built in fields</strong>

**Leads**
`
Human Name API Name
- - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -91,7 +90,32 @@ Rating rating
Annual Rev. revenue
Employees employees
`
<strong>Other Fields</strong>
**Cases**
`
Human Name API Name
- - - - - - - - - - - - - - - - - - - - - - - -
Contact Name ** name

Email email
Phone phone

Subject subject
Description description
Company company

Type * type
Status * status
Case Reason * reason

Priority * priority

Case Origin N/A (not settable via the WebToCase API)

* = must use a value from the picklist defined in your install
** = note that this will be auto prefixed as 'sf_name" in form output and POST data
`

<strong>Other Useful Fields</strong>
`
Lead Source lead_source
Email Opt Out emailOptOut
Expand Down Expand Up @@ -1090,8 +1114,38 @@ function salesforce_w2l_after_submit_example( $post, $form_id, $form_type ){
}
`

**salesforce_w2l_get_prefixed_inputs**

Allows you to add to or change the list of fields that are auto prefixed by the plugin to avoid collisions with WP Query reserved request parameters

`
add_filter('salesforce_w2l_get_prefixed_inputs', 'salesforce_w2l_get_prefixed_inputs_example', 10, 1 );

function salesforce_w2l_get_prefixed_inputs_example( $fields ){
$fields[] = 'new_field_name';
return $fields;
}
`

**salesforce_w2l_input_name_prefix**

Allows you to change the default field name prefix (`_sf`) used to avoid collisions with WP Query reserved request parameters.

`
add_filter('salesforce_w2l_input_name_prefix', 'salesforce_w2l_input_name_prefix_example', 10, 1 );

function salesforce_w2l_input_name_prefix_example( $prefix ){
return 'sfwp2lprefix_';
}
`

== Changelog ==

= 2.7.3.5 =
* Auto prefix field names known to conflict with WP_Query (like `name` in WebToCase). Does not alter other field names for backwards compatibility. Prefix and list of fields to be prefixed is configurable via filters.
* Update tested up to version
* Remove inactive contributors

= 2.7.3.4 =
* Restore missing assets in WordPress.org repository

Expand Down
82 changes: 61 additions & 21 deletions salesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://wordpress.org/plugins/salesforce-wordpress-to-lead/
Description: Easily embed a contact form into your posts, pages or your sidebar, and capture the entries straight into Salesforce CRM. Also supports Web to Case and Comments to leads.
Author: BrilliantPlugins
Version: 2.7.3.4
Version: 2.7.3.5
Author URI: https://brilliantplugins.com/
License: GPL2
*/
Expand Down Expand Up @@ -170,6 +170,38 @@ function salesforce_has_captcha( $form_id, $options ){

}

// known WP_Query reserved request parameters
function salesforce_get_prefixed_inputs(){
$wp_query_reserved = array( 'attachment', 'attachment_id', 'author', 'author_name', 'cat', 'calendar', 'category_name', 'comments_popup', 'cpage', 'day', 'error', 'exact', 'feed', 'hour', 'm', 'minute', 'monthnum', 'more', 'name', 'order', 'orderby', 'p', 'page_id', 'page', 'paged', 'pagename', 'pb', 'post_type', 'posts', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'static', 'subpost', 'subpost_id', 'taxonomy', 'tag', 'tag_id', 'tb', 'term', 'w', 'withcomments', 'withoutcomments', 'year', 'category__in', 'category__not_in', 'category__and', 'comments_per_page', 'offset', 'perm', 'post__in', 'post__not_in', 'post_mime_type', 'post_parent__in', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'meta_key', 'meta_value' );
return apply_filters('salesforce_w2l_get_prefixed_inputs', $wp_query_reserved);
}

// prefix certain field names to avoid collisions with WP Query reserved request parameters
function salesforce_get_input_name( $id ){
$inputs = salesforce_get_prefixed_inputs();

if( in_array( $id, $inputs ) ){
$prefix = apply_filters( 'salesforce_w2l_input_name_prefix', 'sf_' );
return $prefix . $id;
}else{
return $id;
}
}

// un-prefix certain field names to avoid collisions with WP Query reserved request parameters
function salesforce_get_input_id_from_name( $name ){
$inputs = salesforce_get_prefixed_inputs();

$prefix = apply_filters( 'salesforce_w2l_input_name_prefix', 'sf_' );
$id = substr( $name, strlen( $prefix ) + 1 );

if( in_array( $id, inputs ) ){
return $id;
}else{
return $name;
}
}

function salesforce_form($options, $is_sidebar = false, $errors = null, $form_id = 1) {

if( !isset($options['forms'][$form_id]) )
Expand Down Expand Up @@ -233,17 +265,21 @@ function salesforce_form($options, $is_sidebar = false, $errors = null, $form_id
$content .= '<p class="sf_required_fields_msg" id="requiredfieldsmsg"><sup><span class="required">*</span></sup> '.esc_html( $reqtext ).'</p>';

foreach ($options['forms'][$form_id]['inputs'] as $id => $input) {

// get prefixed input name
$input_name = salesforce_get_input_name( $id );

if (!$input['show'])
continue;

if( ! isset( $input['opts'] ) )
$input['opts'] = null;

$val = '';
if ( isset( $_POST[$id] ) ){
$val = $_POST[$id];
if ( isset( $_POST[ $input_name ] ) ){
$val = $_POST[ $input_name ];

if( is_array( $val ) ){
if( is_array( $val ) ){
$val = array_map( 'esc_attr', array_map( 'salesforce_clean_field', $val ) );
}else{
$val = esc_attr(strip_tags(stripslashes($val)));
Expand Down Expand Up @@ -274,13 +310,13 @@ function salesforce_form($options, $is_sidebar = false, $errors = null, $form_id
if ($options['wpcf7css']) { $content .= '<p>'; }
if ($input['type'] == 'checkbox') {

if( isset( $_POST[$id] ) ){
$post_val = $_POST[$id];
if( isset( $_POST[ $input_name ] ) ){
$post_val = $_POST[ $input_name ];
}else{
$post_val = '';
}

$content .= "\t\n\t".'<input type="checkbox" id="sf_'.$id.'" class="w2linput checkbox" name="'.$id.'" value="'.$val.'" '.checked( $post_val, $val, false ).' />'."\n\n";
$content .= "\t\n\t".'<input type="checkbox" id="sf_'.$id.'" class="w2linput checkbox" name="'.$input_name.'" value="'.$val.'" '.checked( $post_val, $val, false ).' />'."\n\n";
}

$placeholder = '';
Expand Down Expand Up @@ -326,31 +362,31 @@ function salesforce_form($options, $is_sidebar = false, $errors = null, $form_id
$content .= "\t".'<input type="text" placeholder="'.$placeholder.'" value="'.$val.'" id="sf_'.$id.'" class="';
$content .= $options['wpcf7css'] ? 'wpcf7-form-control wpcf7-text' : 'w2linput text';
$content .= $options['wpcf7css'] && $input['required'] ? ' wpcf7-validates-as-required required' : '';
$content .= '" name="'.$id.'" '.( !empty($input['opts']) ? ' placeholder="'.$input['opts'].'" title="'.$input['opts'].'"' : '' ).' />'."\n\n";
$content .= '" name="'.$input_name.'" '.( !empty($input['opts']) ? ' placeholder="'.$input['opts'].'" title="'.$input['opts'].'"' : '' ).' />'."\n\n";

}else if ($input['type'] == 'email') {
$content .= "\t".'<input type="email" placeholder="'.$placeholder.'" value="'.$val.'" id="sf_'.$id.'" class="';
$content .= $options['wpcf7css'] ? 'wpcf7-form-control wpcf7-text' : 'w2linput text';
$content .= $options['wpcf7css'] && $input['required'] ? ' wpcf7-validates-as-required required' : '';
$content .= '" name="'.$id.'" '.( !empty($input['opts']) ? ' placeholder="'.$input['opts'].'" title="'.$input['opts'].'"' : '' ).' />'."\n\n";
$content .= '" name="'.$input_name.'" '.( !empty($input['opts']) ? ' placeholder="'.$input['opts'].'" title="'.$input['opts'].'"' : '' ).' />'."\n\n";

}else if ($input['type'] == 'date') {
$content .= "\t".'<input type="text" placeholder="'.$placeholder.'" value="'.$val.'" id="sf_'.$id.'" class="';
$content .= $options['wpcf7css'] ? 'wpcf7-form-control wpcf7-text' : 'w2linput text';
$content .= $options['wpcf7css'] && $input['required'] ? ' wpcf7-validates-as-required required' : '';
$content .= '" name="'.$id.'" />'."\n\n";
$content .= '" name="'.$input_name.'" />'."\n\n";

} else if ($input['type'] == 'textarea') {
$content .= "\t".( !$options['wpcf7css'] ? "\n\n" : '' )."\n\t".'<textarea id="sf_'.$id.'" class="';
$content .= $options['wpcf7css'] ? 'wpcf7-form-control wpcf7-textarea' : 'w2linput textarea';
$content .= $options['wpcf7css'] && $input['required'] ? ' wpcf7-validates-as-required required' : '';
$content .= '" name="'.$id.'"'.( !empty($input['opts']) ? ' placeholder="'.$input['opts'].'" title="'.$input['opts'].'"' : '' ).' placeholder="'.$placeholder.'">'.$val.'</textarea>'."\n\n";
$content .= '" name="'.$input_name.'"'.( !empty($input['opts']) ? ' placeholder="'.$input['opts'].'" title="'.$input['opts'].'"' : '' ).' placeholder="'.$placeholder.'">'.$val.'</textarea>'."\n\n";

} else if ($input['type'] == 'hidden') {
$content .= "\t\n\t".'<input type="hidden" id="sf_'.$id.'" class="w2linput hidden" name="'.$id.'" value="'.$val.'" />'."\n\n";
$content .= "\t\n\t".'<input type="hidden" id="sf_'.$id.'" class="w2linput hidden" name="'.$input_name.'" value="'.$val.'" />'."\n\n";

} else if ($input['type'] == 'current_date') {
$content .= "\t\n\t".'<input type="hidden" id="sf_'.$id.'" class="w2linput hidden" name="'.$id.'" value="'.date($input['opts']).'" />'."\n\n";
$content .= "\t\n\t".'<input type="hidden" id="sf_'.$id.'" class="w2linput hidden" name="'.$input_name.'" value="'.date($input['opts']).'" />'."\n\n";

} else if ($input['type'] == 'html'){
$content .= '<br>'.stripslashes($input['opts'])."\n\n";
Expand All @@ -360,10 +396,10 @@ function salesforce_form($options, $is_sidebar = false, $errors = null, $form_id
$content .= $options['wpcf7css'] ? 'wpcf7-form-control wpcf7-select style-select' : 'w2linput select';
$content .= $options['wpcf7css'] && $input['required'] ? ' wpcf7-validates-as-required required' : '';
if( $input['type'] == 'multi-select' ){
$content .= '" name="'.$id.'[]"';
$content .= '" name="'.$input_name.'[]"';
$content .= ' multiple="multiple" ';
}else{
$content .= '" name="'.$id.'"';
$content .= '" name="'.$input_name.'"';
}
$content .= '>';

Expand Down Expand Up @@ -954,12 +990,16 @@ function salesforce_form_shortcode($atts) {

$has_error = false;


// field validation
foreach ($options['forms'][$form]['inputs'] as $id => $input) {

if( isset( $_POST[$id] ) ){
// get prefixed input name
$input_name = salesforce_get_input_name( $id );

if( isset( $_POST[$input_name] ) ){

$val = $_POST[$id];
$val = $_POST[$input_name];

if( is_array($val) ){
$val = array_map( 'trim', $val );
Expand Down Expand Up @@ -1008,11 +1048,11 @@ function salesforce_form_shortcode($atts) {
// $error = true;
// $emailerror = true;
} else {
if( isset( $_POST[$id] ) ){
if( is_array( $_POST[$id] ) ){
$post[$id] = array_map( 'salesforce_clean_field', $_POST[$id] );
if( isset( $_POST[$input_name] ) ){
if( is_array( $_POST[$input_name] ) ){
$post[$id] = array_map( 'salesforce_clean_field', $_POST[$input_name] );
}else{
$post[$id] = salesforce_clean_field( $_POST[$id] );
$post[$id] = salesforce_clean_field( $_POST[$input_name] );
}
}
}
Expand Down

0 comments on commit e75e9a5

Please sign in to comment.