• Resolved pievedepitti

    (@pievedepitti)


    Hi,
    I have added two other fileds Name and Country in the top bar, but if I set them ad mandatory, then the top bar doesn’t collect data anymore because email shoud be the only required field.
    Any way to set all of the three as mandatory, so to be able to always collect name and country to create my targets?

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

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

    (@lapzor)

    Hi,

    In the code you use to add the fields you can add “required” to the fields.

    eg

    add_action( ‘mctb_before_email_field’, function() {
    echo ‘<label for=”FNAME”>Prénom: </label> <input type=”text” name=”FNAME” placeholder=”Prénom” required />’;
    });

    Hope that helps. If you have any questions, please let me know!

    Thread Starter pievedepitti

    (@pievedepitti)

    Actually, the top bar doesn’ work at all.
    I removed all extra fileds, the log says succesfully subscribed but no new email on the audience list

    Plugin Contributor Lap

    (@lapzor)

    Did you receive the double opt-in mail?
    You need to click the link in the email before the email is subscribed.

    Hope that helps. If you have any questions, please let me know!

    Thread Starter pievedepitti

    (@pievedepitti)

    you’re right, I forgot.
    but NAME field appears as ” even I wrote the full name correctly

    • This reply was modified 4 years, 4 months ago by pievedepitti.
    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey @pievedepitti,

    I regret to say I did not understand your last question. Do you mean the field data from the “FNAME” field is not sent to MailChimp?

    Thread Starter pievedepitti

    (@pievedepitti)

    ok Sorry, I try to explain it better.
    If i write the Name in the top bar as Sara, for example, this text is not collected by mailchimp properly because in the Name column of the Audience, I have just a ” sign. No text, no name, just the double quote mark

    • This reply was modified 4 years, 4 months ago by pievedepitti.
    Plugin Contributor Lap

    (@lapzor)

    Any error in the log on MC4WP > Other?

    Is topbar set to Update emails? Maybe update is set to No and the email already existed with just the ” as name?

    Are you sure the field name is correct for your list?

    Thread Starter pievedepitti

    (@pievedepitti)

    that’s the log

    [2020-11-24 11:05:55] INFO: Top Bar > Successfully subscribed sole********@gm***.com
    [2020-11-24 11:21:16] INFO: Top Bar > Successfully subscribed sole********@gm***.com
    [2020-11-24 11:23:09] INFO: Top Bar > Successfully subscribed risa****@gm***.com

    Yes set to update

    FNAME is ste standard Mailchimp field so….. don’t see any problem with this

    Plugin Contributor Lap

    (@lapzor)

    even though FNAME is the standard field name, it can be renamed so it’s worth checking…

    by the way, i do currently not yet see the required attribute added to the name and country fields yet?

    Thread Starter pievedepitti

    (@pievedepitti)

    no FNAME hasn’t be renamed it’s still *|FNAME|* or *|MERGE1|*
    Which required attribute do you mean?

    Thread Starter pievedepitti

    (@pievedepitti)

    ah..no. Have added it for the name only. Now has been added on both

    • This reply was modified 4 years, 4 months ago by pievedepitti.
    Thread Starter pievedepitti

    (@pievedepitti)

    an other subscriber just registered.
    ” in the name field and country filed is empty (or well it seems not being collected at all)

    I copy my code once again. Maybe It’s my fault I didn’t write it properly.

    add_action( ‘mctb_before_submit_button’, function() {
    echo ‘<input type=”text” name=”FNAME” placeholder=”Name” required/>’;
    echo ‘<input type=”text” name=”MMERGE6” placeholder=”Country – IT” required/>’;
    });

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

    Plugin Contributor Lap

    (@lapzor)

    Is the country field the type “text” or is it the “address type” field?

    I recommend using a normal text field else you need to send in the whole compleet address to pass validation.

    Also there should be just 1 return $vars in the end.

    add_filter( 'mctb_data', function( $vars ) {
    	$vars['FNAME'] = ( isset( $_POST['FNAME'] ) ) ? sanitize_text_field( $_POST['FNAME'] ) : '';
            $vars['MMERGE6'] = ( isset( $_POST['MMERGE6'] ) ) ? sanitize_text_field( $_POST['MMERGE6'] ) : '';
    	return $vars;
    });

    And make sure to use 2 single quotes after the : , I think the WordPress forums turns it into a single curly quote when not using a code block.

    Thread Starter pievedepitti

    (@pievedepitti)

    Yes it’s text. I added a new text field.
    I made changes you suggesteed remove the required flag on mailchimp filed Name and Coutry (both text) but again, name is collected as ” , Country is not collected at all

    • This reply was modified 4 years, 4 months ago by pievedepitti.
    Thread Starter pievedepitti

    (@pievedepitti)

    moreover, if I put same email on the bar, once the user has been subscribed already, I don’t get the message you’re subscribed already event this message has been set in the plugin options

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘how to add other mandatory fields than email’ is closed to new replies.