0

I want to add a function to my registration form, which allows to validate one of the fields which is the following: REFERRED BY.

example: if the user "Stack" refers me to the platform I must put "Stack" in the field.

the function must validate that this user exists and thus allow the registration, in case the user does not exist it must give error.

I have tried with the following code but I need to know how to check if that user name is in the database.

the realization of the code was based on these official posts of the plugin

https://wpforms.com/developers/wpforms_post_submissions_post_args/

https://wpforms.com/developers/wpforms_entry_save_args/

/**
 * Action that fires during form submission.
 *
 * 
 *
 * @param  array  $post_args Sanitized entry field. values/properties.
 * @param  array  $form_data Form data and settings.
 * @param  array  $fields    Sanitized entry field values/properties.
 *
 * @return array
 */
        function wpf_dev_post_submissions_post_args( $post_args, $form_data, $fields ) {

       //we check which form will be changed

            if ( absint( $form_data['id'] ) !== 881 ) {
                return $fields;
            }
        
    //We will work with field 12 which is the one I need to verify and value will be the username that the new user should put. 

    //user that the new user should put, I don't know what should go in the === to check the user name. 
    //and I wouldn't know what I should return either`.
    
            if ( ! empty( $fields['12'] ) && $fields['12']['value'] ===  ) 
            }
            return $post_args;
        }
           
        add_filter( 'wpforms_post_submissions_post_args', 'wpf_dev_post_submissions_post_args', 10, 3 );
1
  • Have you reached out to WPForms support? Jan 23 at 18:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.