• Resolved tamjohnston01

    (@tamjohnston01)


    Hi there,
    I have 3 fields in my mailchimp signup. I’ve seen the post and support on how to add a name field, but how could I add 2 extra fields – first and last name? There’s certainly plenty of room on the topbar! The mailchimp tags are FNAME and LNAME

    I have tried placing this in my functions file (child theme) but it’s only showing surname.
    add_action( ‘mctb_before_surname_field’, function() {
    echo ‘<input type=”text” name=”FNAME” placeholder=”First name” />’;
    });

    add_action( ‘mctb_before_email_field’, function() {
    echo ‘<input type=”text” name=”LNAME” placeholder=”Surname” />’;
    });
    add_filter( ‘mctb_merge_vars’, function( $vars ) {
    $vars[‘NAME’] = ( isset( $_POST[‘ FNAME’] ) ) ? sanitize_text_field( $_POST[‘FIRST NAME’] ) : ”;
    return $vars;
    });
    add_filter( ‘mctb_merge_vars’, function( $vars ) {
    $vars[‘NAME’] = ( isset( $_POST[‘LNAME’] ) ) ? sanitize_text_field( $_POST[‘SURNAME’] ) : ”;
    return $vars;
    });

    Your help would be really appreciated. Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I got this working on my bar by using the following. Hope it helps. Basically you have to add two actions, one for a field of first name, the second for the last name. Feel free to see it on my wife’s food blog at https://www.grabsomejoy.com

    add_action( ‘mctb_before_email_field’, function() {
    echo ‘<input type=”text” name=”FNAME” placeholder=”First Name” required>’;
    echo ‘<input type=”text” name=”LNAME” placeholder=”Last Name” required>’;

    });

    add_filter( ‘mctb_merge_vars’, function( $vars ) {
    $vars[‘FNAME’] = ( isset( $_POST[‘FNAME’] ) ) ? sanitize_text_field( $_POST[‘FNAME’] ) : ”;
    return $vars;
    });

    add_filter( ‘mctb_merge_vars’, function( $vars ) {
    $vars[‘LNAME’] = ( isset( $_POST[‘LNAME’] ) ) ? sanitize_text_field( $_POST[‘LNAME’] ) : ”;
    return $vars;
    });

    Thread Starter tamjohnston01

    (@tamjohnston01)

    @bhensley

    Thankyou so, so much! Forgive the delay, I took a break over the holiday period. Your comment is hugely appreciated, thankyou for taking the time. That worked brilliantly, although I did have to do some tweaking of quotation marks from cutting and pasting yours to avoid parsing errors! For anyone else wanting to do this, here’s the code I found that works, as long as it copies well for you!

    add_action( ‘mctb_before_email_field’, function() {
    echo ‘<input type=”text” name=”FNAME” placeholder=”First Name” required />’;
    echo ‘<input type=”text” name=”LNAME” placeholder=”Last Name” required />’;
    });

    add_filter( ‘mctb_merge_vars’, function( $vars ) {
    $vars[‘FNAME’] = ( isset( $_POST[‘FNAME’] ) ) ? sanitize_text_field( $_POST[‘FNAME’] ) : ”;
    return $vars;
    });

    add_filter( ‘mctb_merge_vars’, function( $vars ) {
    $vars[‘LNAME’] = ( isset( $_POST[‘LNAME’] ) ) ? sanitize_text_field( $_POST[‘LNAME’] ) : ”;
    return $vars;
    });

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘first and lastname’ is closed to new replies.