• Hi there,
    I’m using classipress theme and I addedd some extra field-s on user registration like name and lastname. My problem is that somethimes, name and last name are inserted into database, and somethimes not. I don’t get it what I’m doing wrong.

    On the template page it look’s like this:

    <label for="first_name"><?php _e('Ime:', 'APP_TD'); ?></label>
    <input tabindex="2" class="text" type="text" class="text required" name="first_name" id="first_name" value=<?php if (isset($_POST['first_name'])) echo esc_attr(stripslashes($_POST['first_name'])); ?>>
    
    <label for="last_name"><?php _e('Prezime:', 'APP_TD'); ?></label>
    <input tabindex="3" class="text" type="text" class="text required" name="last_name" id="last_name" value=<?php if (isset($_POST['last_name'])) echo esc_attr(stripslashes($_POST['last_name'])); ?>>

    and in the function file of the theme I added this:

    function at_validate_custom_fields( $login, $email, $errors ) {
    
      // fields to be validated
      $fields = array(
    	'first_name' => __( 'Ime:', 'APP_TD' ),
    	'last_name' => __( 'Prezime:', 'APP_TD' ),
      );
    
      // check for empty required fields an display notice
      foreach ( $fields as $field => $value ) {
    	if ( empty( $_POST['first_name'] ) ) {
    		$errors->add('empty_fields', __('<strong>GREŠKA</strong>: Niste uneli ime.', 'APP_TD'));
    	}
    	if ( empty( $_POST['last_name'] ) ) {
    		$errors->add('empty_fields', __('<strong>GREŠKA</strong>: Niste uneli prezime.', 'APP_TD'));
    	}
      }
    
      // check for invalid names (letters and spaces)
      if ( ! empty( $_POST['first_name'] ) && !preg_match("/^[\p{L} ]+$/u", $_POST['first_name']) ) {
    	$errors->add('invalid_name', __('<strong>GREŠKA</strong>: “', 'APP_TD').$fields['first_name'].__('” u polje za ime trebate upisati samo slova.', 'APP_TD'));
      }
      if ( ! empty( $_POST['last_name'] ) && !preg_match("/^[\p{L} ]+$/u", $_POST['last_name']) ) {
    	$errors->add('invalid_name', __('<strong>GREŠKA</strong>: “', 'APP_TD').$fields['last_name'].__('” u polje za prezime trebate upisati samo slova.', 'APP_TD'));
      }  
    
    // additional custom fields validations here
    
    }
    // validate custom fields
    add_action( 'register_post', 'at_validate_custom_fields', 10, 3 );
    
    // register the extra fields as user metadata
    function at_register_custom_fields( $user_id, $password = "", $meta = array() )  {
    
    	// custom fields
    	$fields = array(
    		'first_name',
    		'last_name',
    	);
            // cleans and updates the custom fields
    	foreach ( $fields as $field ) {
    	    $value = stripslashes( trim( $_POST[$field] ) ) ;
    	    if ( ! empty( $value ) ) {
    	  	 update_user_meta( $user_id, $field, $value );
    	    }
    	}
    
    }
    
    // save the custom fields to the database as soon as the user is registered on the database
    add_action( 'user_register', 'at_register_custom_fields' );

    since I changeg defaulf displaying name like this:

    add_action('user_register', 'registration_save_displayname', 1000);
    function registration_save_displayname($user_id) {
        if ( isset( $_POST['first_name']) &&  isset( $_POST['last_name']) ){
    		$pretty_name = $_POST['first_name'] . ' '. $_POST['last_name'];
    		wp_update_user( array ('ID' => $user_id, 'display_name'=> $pretty_name) ) ;
    	}
    }

    this is always saved in database, but name and lastname fields, not.

Viewing 1 replies (of 1 total)
  • Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    As that is a commercial theme, we ask that you please go to their official support channel. In order to be good stewards of the WordPress community, and encourage innovation and progress, we feel it’s important to direct people to those official locations.

    http://www.appthemes.com/support/

    Forum volunteers are also not given access to commercial products, so they would not know why your commercial theme is not working properly. This is one other reason why volunteers forward you to the commercial product’s vendors. The vendors are responsible for supporting their commercial product.

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with adding name and lastname on registration’ is closed to new replies.