Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Vendors › How get custom fields vendor registration to use validation ?
- This topic has 1 reply, 2 voices, and was last updated 4 years, 6 months ago by Sarmistha Chakraborty.
- AuthorPosts
- May 8, 2020 at 12:53 am #128162lukas_smithParticipant
I have own fields as HTML with own name
<input type="text" maxlength="26" id="bank_account-100" name="wcfmvm_custom_infos[bank_account]" onkeypress="return event.charCode >= 48 && event.charCode <= 57" class="wcfm-text" value="" placeholder="" data-required="1" data-required_message="Acc no. this field is req.">
What i need to do is when i click registration i would add filtr with own function in there for this fields name
wcfmvm_custom_infos[bank_account]
and calculate is bank acc no is correct? If not return false with messageIs any way to do this using filter ? i dont wanna change code in core fiels
- May 8, 2020 at 3:35 pm #128367Sarmistha ChakrabortyMember
Hello,
Add this js in your theme’s js file –
jQuery(document).ready(function ($) { if($('#wcfm_membership_registration_form #bank_account').length > 0) { $( document.body ).on( 'wcfm_form_validate', function( event, validating_form ) { $form = $(validating_form); $wcfm_is_valid_form = false; var is_valid = checkStrength($('#bank_account').val()); if(is_valid) { $wcfm_is_valid_form = true; } else { $('#bank_account').removeClass('wcfm_validation_success').addClass('wcfm_validation_failed'); $('#bank_account').addClass('wcfm_validation_failed'); $('#wcfm_membership_container .wcfm-message:not(.email_verification_message, .sms_verification_message)').html( '<span class="wcicon-status-cancelled"></span>' + $('#bank_account').data('mismatch_message') ).addClass('wcfm-error').slideDown(); $wcfm_is_valid_form = false; } }); } function checkStrength(accno) { if(isNaN(accno)){ return $wcfm_is_valid_form = false; } else { return $wcfm_is_valid_form = true; } } });
And add this code in your theme’s functions.php –
add_filter( 'wcfm_membership_registration_fields_username', function( $wcfm_register_field ) { $wcfm_register_field["bank_account"] = array( 'label' => __('Bank account', 'wc-multivendor-membership') , 'type' => 'text', 'custom_attributes' => array( 'required' => 1 , 'required_message' => __( 'Acc no. this field is req.', 'wc-multivendor-membership' ),'mismatch_message' => __( 'Invalid Bank Account Number.', 'wc-multivendor-membership' ) ), 'class' => 'wcfm-text wcfm_ele ', 'label_class' => 'wcfm_ele wcfm_title', 'value' => $bank_account ); return $wcfm_register_field; },15);
Thanks.
- AuthorPosts
- You must be logged in to reply to this topic.