Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Interactive Profile Fields During Registration (27 posts)

Started 3 months, 4 weeks ago by: davidveldt

  • Profile picture of davidveldt davidveldt said 3 months, 4 weeks ago:

    Hello Everyone,

    I believe this topic has been asked before, and I’ve seen it on the Wordpress forum but it hasn’t been resolved, so I wanted to bring it up again.

    I’d like to make my registration form a little more interactive. Meaning, different profile fields depending on which type of user you select at the beginning. On my site (an athletic site), users can indicate whether they are a player, coach, parent or instructor. If you are a player, I want questions pertaining to their position, for example, to show. If you are an instructor, you may be interested in displaying your company name or website and so on.

    Does anyone have any ideas on how to accomplish this? Currently, profile fields are heavily geared towards players and it seems awkward for other users. Any ideas would be much appreciated. Thanks in advance

  • Profile picture of Paul Gibbs Paul Gibbs said 3 months, 4 weeks ago:

    Sounds like a lot of info for the sign up form. What about jus putting a dropdown with the ‘person type’ in the first profile field group (which is the one that appears on the registration page by default), and then putting further type-specific fields into their own profile groups.

    With a little bit of coding, you can deny visibility or access to these other profile groups depending on user type, without too much diffficulty.

  • Profile picture of davidveldt davidveldt said 3 months, 4 weeks ago:

    Hmmm good point. Definitely worth checking out, however I still run into figuring out how to show/hide info depending on what they select from the drop-down. Not sure how to go about this…

  • Profile picture of Marcella Marcella said 3 months, 4 weeks ago:

    Just an example here, running with Paul Gibbs start point.

    Create xprofile fields as normal.

    Each career group would also have its own xprofile group.

    Player would have his / her own set of fields.
    Coach would have his / her own set of fields.
    Parent would have his / her own set of fields.
    Instructor would have his / her own set of fields.

    None of the above would be required fields. (as far as BuddyPress is concerned (unless you roll some PHP codes))

    You’d have another xprofile group specifically for required fields (this would be your first group).

    You would make the “type” part of the required group and set it as a select box.

    You could then write your registration form mark-up matching the requirements of jQuery tabs or jQuery accordion.

    The “type” would be the last item on the required fields. Once that was selected you could then show or hide the corresponding jQuery ui-tab-panel that holds those form fields.

    You could then on-the-fly make those fields then required using some jQuery also but a bit hacky.

  • Profile picture of davidveldt davidveldt said 3 months, 4 weeks ago:

    @Marcella,

    Yeah, that’s how I pictured it as well. Trouble is, I’m not great with jQuery so that’s going to take some studying up. This project might be saved for a rainy day.

  • Profile picture of Marcella Marcella said 3 months, 4 weeks ago:

    Oh I can help you with that, lemme set up a local test area.

  • Profile picture of Marcella Marcella said 3 months, 4 weeks ago:

    Hey @davidveldt this should do it if you are using the default theme. Otherwise you should integrate as you see fit.

    theme/registration/register.php

    You can add any groups or fields as you require. The groups and fields here are arbitrary.

    <?php  $roles = array(2 => 'player', 4 => 'coach', 5 =>'parent', 6 => 'instructor'); ?>
    <div id="roles">
    <?php foreach($roles as $key => $role) : ?>
    <div id="<?php echo $role; ?>" class="role-fields">
    	<?php if(bp_has_profile('profile_group_id='.$key)) : while(bp_profile_groups()) : bp_the_profile_group(); ?>
    		<?php while(bp_profile_fields()) : bp_the_profile_field(); ?>
    			<div class="editfield">
    				<?php if('textarea' == bp_get_the_profile_field_type()) : ?>
    					<label for="<?php bp_the_profile_field_input_name() ?>"><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ) ?><?php endif; ?></label>
    					<?php do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ) ?>
    					<textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"><?php bp_the_profile_field_edit_value() ?></textarea>
    				<?php endif; ?>
    		    	<?php do_action( 'bp_custom_profile_edit_fields' ) ?>
    		        <p class="description"><?php bp_the_profile_field_description() ?></p>
    		    </div>
    		<?php endwhile; ?>
    		<input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="<?php bp_the_profile_group_field_ids() ?>" />
    	<?php endwhile; endif; ?>
    </div>
    <?php endforeach; ?>
    </div>

    Create some profile groups to cater for each role. You can find the group id within the BuddyPress admin… In the url bar or investigate your database.

    You should set-up the $roles array above to match your requirements.

    Within the loop you can show any fields you have created within that xprofile group. If you have a select box within that group you would add the following code as outlined in the bp-default register.php

    <?php if ( 'selectbox' == bp_get_the_profile_field_type() ) : ?>
    
    									<label for="<?php bp_the_profile_field_input_name() ?>"><?php bp_the_profile_field_name() ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ) ?><?php endif; ?></label>
    									<?php do_action( 'bp_' . bp_get_the_profile_field_input_name() . '_errors' ) ?>
    									<select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>">
    										<?php bp_the_profile_field_options() ?>
    									</select>
    
    								<?php endif; ?>

    Finally add the following jQuery where you house any other code of similar ilk.

    <script>
    	jQuery(".role-fields").hide();
    	$roles = jQuery("#roles");
    	jQuery("#field_2").change(function()
    	{
    		$role = jQuery(this).val().toLowerCase();
    		jQuery(".role-fields").hide();
    		jQuery("#" + $role).toggle();
    	});
    	</script>

    Here’s a pastebin for all that above. http://pastebin.com/QFdTdstz

    No need for tabs or accordion this time.

    Hope that helps you on the Road.

  • Profile picture of bojan85 bojan85 said 3 months, 3 weeks ago:

    not to hijack this thread but Wow this was exactly what I have been looking for but being a beginner this would be hard for me to implepement….no thoughts of relasing this as a plugin marcella?

  • Profile picture of Marcella Marcella said 3 months, 3 weeks ago:

    hey dude, all depends on how many people would want it as a plugin and it may have already been done before.

    with David having a very specific case it was ok here but would need some more work to be practical.

    if you need some help getting something like this working you could describe what you need, what theme you have etc and maybe take it from there.

  • Profile picture of davidveldt davidveldt said 3 months, 3 weeks ago:

    @Marcella,

    Wow! What a thoughtful and detailed reply! Thank you so much for all of this.

    ps. A plugin would be AWESOME – you now have 2 votes (gotta start somewhere!)

  • Profile picture of Marcella Marcella said 3 months, 3 weeks ago:

    If you could stub out the functionality of the plugin I’d be happy to consider it :)

  • Profile picture of bojan85 bojan85 said 3 months, 3 weeks ago:

    @marcella1981,

    Hey Marcella, first of all thank you for taking the time to help us, What I am trying to do is very similar as david have two different registration forms depending if their user role is an athlete or coach. I have the regular Bp default theme with the frisco theme, and latest wp and bp.

    I have been trying to figure it out for a couple days but cant seem to move forward..where in the register.php do i enter the php code and jquery script? I tried a couple different places..I have matched the group fields with the $roles array I’m guessing thats the only thing im doing right so far…

    Sorry for the all the questions I am a beginner at all this..Any tips or help how to move forward would be greatly appreciated!

  • Profile picture of Marcella Marcella said 3 months, 3 weeks ago:

    Hey @bojan85

    Guess there is a small need for a plugin like this.

    I’m trying to visualise how you would configure a plugin to meet the requirements you need and also any others like @davidveldt

    Possible scenarios?

    Multiple routes for registration depending on which items were selected at the “required” stage.

    If this was to come “out the box” with BuddyPress, how would you expect to set this registration up within wp-admin / bp-admin?

  • Profile picture of bojan85 bojan85 said 3 months, 3 weeks ago:

    @marcella1981
    I think a plugin would be a great addition to bp..I would believe more users would like to be able to create different registration profile fields for different users (dating sites, networking sites, job sites etc.,..that’s a good question..maybe something simple in the bp admin like the buddypress user account type plugin…or maybe is it possible to create the plugin as add on to the main Extended Profile Fields menu?

    I wish I could be more of a help..
    Cheers, Bojan

  • Profile picture of abyss abysshorror said 3 months, 3 weeks ago:

    @marcella1981 +1 plugin :)