Please tell me if I am on the right path?
if($_POST['wpforms[id]'] == "7408") {
$subscriber->merge_fields[ "FNAME" ] = sanitize_text_field( $_POST['wpforms[fields][12][first]'] );
$subscriber->merge_fields[ "LNAME" ] = sanitize_text_field( $_POST['wpforms[fields][12][last]'] );
$subscriber->merge_fields[ "COMPANY" ] = sanitize_text_field( $_POST['wpforms[fields][4][company]'] );
$subscriber->merge_fields[ "PHONE" ] = sanitize_text_field( $_POST['wpforms[fields][11][phone]'] );
}
Not sure if I’m writing the correct values at the end of the row.
Where does the value come from?
View post on imgur.com
Plugin Contributor
Lap
(@lapzor)
When you view the form on your site you can right click > inspect to see the source code. There you want to find the name=”..” part of each input field.
Hope that helps. If you have any questions, please let me know!
I seem to be getting this error
Warning: Undefined array key "wpforms[id]" in /usr/www/users/nerosnmxpd/sk.nerospec.com/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()'d code on line 7 Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/nerosnmxpd/sk.nerospec.com/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()'d code:7) in /usr/www/users/nerosnmxpd/sk.nerospec.com/wp-includes/pluggable.php on line 1421 Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/nerosnmxpd/sk.nerospec.com/wp-content/plugins/code-snippets/php/snippet-ops.php(505) : eval()'d code:7) in /usr/www/users/nerosnmxpd/sk.nerospec.com/wp-includes/pluggable.php on line 1424
It seems that the form submitted and the double opt-in went through. It’s just the page loading a white screen with an error
Hey @nerospec,
Can you please do a quick test by removing the custom code and testing the form again?
The form submits fine. Just no field remapping
I tried a different code inserter. It seems to have removed the error, but the remapping is not working. Is this code correct?
// The problem with WPForms forms in this regard is that it generates field names that aren't always easy for our plugin to recognize.
// You will have to inspect the source of the form to find field names (name="...") for each field and manually map them as such:
add_filter( 'mc4wp_integration_wpforms_subscriber_data', function( MC4WP_MailChimp_Subscriber $subscriber ) {
//Become a Distributor
if($_POST['wpforms[id]'] == "7408") {
$subscriber->merge_fields[ "FNAME" ] = sanitize_text_field( $_POST['wpforms[fields][12][first]'] );
$subscriber->merge_fields[ "LNAME" ] = sanitize_text_field( $_POST['wpforms[fields][12][last]'] );
$subscriber->merge_fields[ "COMPANY" ] = sanitize_text_field( $_POST['wpforms[fields][4]'] );
$subscriber->merge_fields[ "PHONE" ] = sanitize_text_field( $_POST['wpforms[fields][11]'] );
}
return $subscriber;
});
View post on imgur.com
View post on imgur.com
View post on imgur.com
View post on imgur.com
Plugin Contributor
Lap
(@lapzor)
The error is a warning that the wpforms[id] field can’t be found in the submission…
We could remove that if statement but that it will apply to each WpForm, not just the form with that ID.
How are the field names different in another form? Maybe we can change the if statement to look for those fields instead of the form ID.
Thanks for letting me know.