• Resolved goeduc

    (@goeduc)


    Is it possible to have two name fields – First and last? I already have a list with both fields, and I would like to continue to use it.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Lap

    (@lapzor)

    Hi,

    You can adapt this snippet to have 2 fields:
    https://github.com/ibericode/mc4wp-snippets/blob/master/add-ons/top-bar/add-name-field.php

    e.g.

    <?php
    /**
     * Echo a NAME field just before the submit button.
     */
    add_action( 'mctb_before_submit_button', function() {
    	echo '<input type="text" name="FNAME" placeholder="Your name" />';
    	echo '<input type="text" name="LNAME" placeholder="Your name" />';
    });
    /**
     * Make sure the content of the NAME field is sent to MailChimp
     *
     * @param array $vars
     */
    add_filter( 'mctb_data', function( $vars ) {
    	$vars['FNAME'] = ( isset( $_POST['NAME'] ) ) ? sanitize_text_field( $_POST['NAME'] ) : '';
    	$vars['LNAME'] = ( isset( $_POST['NAME'] ) ) ? sanitize_text_field( $_POST['NAME'] ) : '';
    	return $vars;
    });
    pohly

    (@pohly)

    Hi,
    I tried this and it nicely modified the mc4wp top bar even with ‘mctb_before_ email_field’ and translating “your name”.
    However there was no transfer to mc although fname and lname were defined in mc.

    Here is the script:
    <?php /** * Echo a NAME field just before the submit button. */ add_action( ‘mctb_before_ email_field’, function() { echo ‘<input type=”text” name=”FNAME” placeholder=”Vorname” />’; echo ‘<input type=”text” name=”LNAME” placeholder=”Nachname” />’; }); /** * Make sure the content of the NAME field is sent to MailChimp * * @param array $vars */ add_filter( ‘mctb_data’, function( $vars ) { $vars[‘FNAME’] = ( isset( $_POST[‘NAME’] ) ) ? sanitize_text_field( $_POST[‘NAME’] ) : ”; $vars[‘LNAME’] = ( isset( $_POST[‘NAME’] ) ) ? sanitize_text_field( $_POST[‘NAME’] ) : ”; return $vars; });

    Does anybody have a hint?

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hi @pohly,

    The snippet my colleague posted is not entirely correct. It adds the first- and last-name fields, but does not yet add these fields to the data that is sent to Mailchimp.

    The following should do the trick:

    
    /**
     * Echo a NAME field just before the submit button.
     */
    add_action( 'mctb_before_submit_button', function() {
    	echo '<input type="text" name="FNAME" placeholder="Your name" />';
    	echo '<input type="text" name="LNAME" placeholder="Your name" />';
    });
    /**
     * Make sure the content of the NAME field is sent to MailChimp
     *
     * @param array $vars
     */
    add_filter( 'mctb_data', function( $vars ) {
    	$vars['FNAME'] = ( isset( $_POST['FNAME'] ) ) ? sanitize_text_field( $_POST['FNAME'] ) : '';
    	$vars['LNAME'] = ( isset( $_POST['LNAME'] ) ) ? sanitize_text_field( $_POST['LNAME'] ) : '';
    	return $vars;
    });
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is it possible to have two name fields?’ is closed to new replies.