• Resolved asadhhabib

    (@asadhhabib)


    I’ve added several fields to the registration form but they are not being persisted to the database. The code is as follows:

    <?php
    
    	function tml_registration_errors( $errors ) {
    		if ( empty( $_POST['first_name'] ) )
    			$errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
    
    		if ( empty( $_POST['last_name'] ) )
    			$errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
    
    		if ( empty( $_POST['address'] ) )
    			$errors->add( 'empty_address', '<strong>ERROR</strong>: Please enter your address.' );
    	
    		if ( empty( $_POST['country'] ) )
    			$errors->add( 'empty_country', '<strong>ERROR</strong>: Please enter your country.' );
    
    		if ( empty( $_POST['phone'] ) )
    			$errors->add( 'empty_phone', '<strong>ERROR</strong>: Please enter your phone.' );
    
    		if ( empty( $_POST['qualification'] ) )
    			$errors->add( 'empty_qualification', '<strong>ERROR</strong>: Please enter your qualification and/or specialization.' );
    
    		/* if ( empty( $_POST['primary_workplace'] ) || ( $_POST['primary_workplace'] == 'Select Primary Workplace') )
    			$errors->add( 'empty_primary_workplace', '<strong>ERROR</strong>: Please enter your primary workplace.' );
    
    		if ( empty( $_POST['years_practicing_medicine'] ) || ( $_POST['years_practicing_medicine'] == 'Select Number of Years') )
    			$errors->add( 'empty_years_practicing_medicine', '<strong>ERROR</strong>: Please enter your years practicing medicine.' );
    
    		if ( empty( $_POST['currently_complete_death_certificates'] ) )
    			$errors->add( 'empty_currently_complete_death_certificates', '<strong>ERROR</strong>: Please indicate whether you are currently completing death certificates.' );
    
    		if ( empty( $_POST['taught_to_complete_death_certificate'] ) )
    			$errors->add( 'empty_taught_to_complete_death_certificate', '<strong>ERROR</strong>: Please indicate whether you were ever taught to complete a death certificate.' );
    
    		if ( empty( $_POST['complete_death_certificates_correctly'] ) )
    			$errors->add( 'empty_complete_death_certificates_correctly', '<strong>ERROR</strong>: Please indicate whether you think you usually complete death certificates correctly.' ); */
    
    		return $errors;
    	}
    
    	add_filter( 'registration_errors', 'tml_registration_errors' );
    
    	function tml_user_register( $user_id ) {
    		print_r('Hello');
    
    		if ( !empty( $_POST['first_name'] ) )
    			update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
    
    		if ( !empty( $_POST['last_name'] ) )
    			update_user_meta( $user_id, 'last_name', $_POST['last_name'] );
    
            	if ( !empty( $_POST['address'] ) )
    			update_user_meta( $user_id, 'address', $_POST['address'] );
    
    		if ( !empty( $_POST['country'] ) )
    			update_user_meta( $user_id, 'country', $_POST['country'] );
    
    		if ( !empty( $_POST['phone'] ) )
    			update_user_meta( $user_id, 'phone', $_POST['phone'] );
    
    		if ( !empty( $_POST['qualification'] ) )
    			update_user_meta( $user_id, 'qualification', $_POST['qualification'] );
    
    		if ( !empty( $_POST['primary_workplace'] ) && ( $_POST['primary_workplace'] !== 'Select Primary Workplace') )
    			update_user_meta( $user_id, 'primary_workplace', $_POST['primary_workplace'] );
    
    		if ( !empty( $_POST['mci_number'] ) )
    			update_user_meta( $user_id, 'mci_number', $_POST['mci_number'] );
    
    		if ( !empty( $_POST['years_practicing_medicine'] ) && ( $_POST['years_practicing_medicine'] != 'Select Number of Years') )
    			update_user_meta( $user_id, 'years_practicing_medicine', $_POST['years_practicing_medicine'] );
    
    		if ( !empty( $_POST['currently_complete_death_certificates'] ) )
    			update_user_meta( $user_id, 'currently_complete_death_certificates', $_POST['currently_complete_death_certificates'] );
    
    		if ( !empty( $_POST['taught_to_complete_death_certificate'] ) )
    			update_user_meta( $user_id, 'taught_to_complete_death_certificate', $_POST['taught_to_complete_death_certificate'] );
    
    		if ( !empty( $_POST['teaching_location'] ) )
    			update_user_meta( $user_id, 'teaching_location', $_POST['teaching_location'] );
    
    		if ( !empty( $_POST['complete_death_certificates_correctly'] ) )
    			update_user_meta( $user_id, 'complete_death_certificates_correctly', $_POST['complete_death_certificates_correctly'] );
    	}
    
    	add_action( 'user_register', 'tml_user_register' );
    ?>

    What am I doing wrong? I checked the syntax of the PHP code and it is correct. Any help would be much appreciated. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter asadhhabib

    (@asadhhabib)

    I’ve figured out my problem. Thanks.

    @asadhhabib

    Hello Sir.

    Can you guide me and maybe share your modified files and let me know where to place exactly to make it working.
    I have try`t everything and it does not save the new added fields in the user fields.
    Maybe you can write a small easy guide to help.
    I actually only need 2 extra fields like First Name/ Last Name/ , i followed the guide here http://docs.thememylogin.com/ but i can`t get it to work ;(

    Thanks in advance.

    Best regards,

    ysco..

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

The topic ‘New Registration Fields’ is closed to new replies.