Title: custom required field to load Javascript
Last modified: April 29, 2021

---

# custom required field to load Javascript

 *  Resolved [gteyespy](https://wordpress.org/support/users/gteyespy/)
 * (@gteyespy)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/)
 * Is there a way to create a custom required text field for a “sales” code that
   will identify the User as part of the “sales” group
 * the logic behind this is for tracking sales which is loaded in a JS
    and need
   a unique way to upon registration to enter code “sales”.
 * when “sales” code is registered it needs to load a unique JS for the user that
   registered with the “sales” promotion
 * form sample:
    first name – last name – email – phone – promo code
 * if promo code = XYZ123
    load JS file A
 * if user is logged-in pages load with JS associated with promo code
 * is this even capable with Ultimate Member?
    Is this a custom JS to load based
   on “promo code”?
 * i could really use the help.
 * SOS
 * Thanks
 * G

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14382598)
 * Hi [@gteyespy](https://wordpress.org/support/users/gteyespy/)
 * Unfortunately, this requires customization on your end.
    Have you set up a custom
   post type or a new database table for the promo code? Or is the promo code static
   or just a few numbers of Promo code?
 * Regards,
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14396716)
 * Hey there!
 *  This thread has been inactive for a while so we’re going to go ahead and mark
   it Resolved.
 * Please feel free to re-open this thread by changing the Topic Status to ‘Not 
   Resolved’ if any other questions come up and we’d be happy to help. 🙂
 * Regards,
 *  Thread Starter [gteyespy](https://wordpress.org/support/users/gteyespy/)
 * (@gteyespy)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14400087)
 * Sorry for the late reply as I was on Holiday
 * I think the best route would be a new table in the DB
 * but i guess my question really is how do connect the form field (text) registration
   form as required and the db table to check if refferer code is valid.
 * Then i can write a JS that says If user referral code equals A then load JS A.
   else equals B Load JS B . . etc.
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14401061)
 * Hi [@gteyespy](https://wordpress.org/support/users/gteyespy/)
 * You can create a new field with custom validation. Please see this doc explaining
   how to add a custom validation in PHP:
    [https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-field](https://docs.ultimatemember.com/article/94-apply-custom-validation-to-a-field)
 * Regards,
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14423690)
 * Hey there!
 *  This thread has been inactive for a while so we’re going to go ahead and mark
   it Resolved. ..Please feel free to re-open this thread by changing the Topic 
   Status to ‘Not Resolved’ if any other questions come up and we’d be happy to 
   help. 🙂
 * Regards,
 *  Thread Starter [gteyespy](https://wordpress.org/support/users/gteyespy/)
 * (@gteyespy)
 * [5 years ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14436069)
 * i saw this and this is where i need help as i’m a PHP newb.
 * where do I put in the parameter for the list i want to accept as the invite code.
   
   i.e dog, cat, bird, fish
 * i’m sorry for the stupid qestion. i’m just new at this.
 * /**
    * Validate field Invitation Code * [@param](https://wordpress.org/support/users/param/)
   string $key * [@param](https://wordpress.org/support/users/param/) attay $array*
   [@param](https://wordpress.org/support/users/param/) array $args */ function 
   um_custom_validate_invite( $key, $array, $args ) { if ( isset( $args[$key] ) &&!
   preg_match(‘dog, cat, bird, fish’, $args[$key]) ) { UM()->form()->add_error( 
   $key, __( ‘Please enter valid Invitation code.’, ‘ultimate-member’ ) ); } } add_action(‘
   um_custom_field_validation_invite’, ‘um_custom_validate_invite’, 30, 3 );`
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14760878)
 * Hi [@gteyespy](https://wordpress.org/support/users/gteyespy/)
 * Sorry for the late response.
 * You can try this code snippet:
 *     ```
       function um_custom_validate_invite( $key, $array, $args ) {
       if ( isset( $args[$key] ) && ! in_array( $args[$key],['dog','cat','bird','fish']) ) {
       UM()->form()->add_error( $key, __( ‘Please enter valid Invitation code.’, ‘ultimate-member’ ) );
       }
       }
       add_action( ‘um_custom_field_validation_invite’, ‘um_custom_validate_invite’, 30, 3 );
       ```
   
 * The above code will check if the Invite code doesn’t match the input. If the 
   input is not from the list(‘dog’,’cat’,’bird’,’fish’), it will throw `Please 
   enter valid Invitation code.`
 * Feel free to re-open this thread if there’s any question that may come up.
 * Regards,

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘custom required field to load Javascript’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/custom-required-field-to-load-javascript/#post-14760878)
 * Status: resolved