Removing fields from sign up page


(12 posts) (2 voices)
  • Started 11 months ago by achtermijnpc
  • Latest reply from achtermijnpc

Tags:

  1. achtermijnpc
    Member

    I know, the discussions here are more “general” related, I had a php question which is actually more related to bbPress.

    My question is, how to show less fields on the sign up page, but keep the fields on the profile page.

    I will explain this with images:

    http://i950.photobucket.com/albums/ad346/metalsuriname/aanmelden.png

    http://i950.photobucket.com/albums/ad346/metalsuriname/profielpagina.png

    understand?

    Posted 11 months ago #
  2. No worries!

    In register.php file of your bbPress theme the following line is responsible for generating the input fields
    <input name="<?php echo $key; ?>" type="text" id="<?php echo $key; ?>" size="30" maxlength="140" value="<?php echo $$key; ?>" />

    You can use a php condition to check the values of the $key here and if its from the permitted list, then only this statement should be parse else by-pass it.

    Hope that helps! :)

    Posted 11 months ago #
  3. Ok! Here you go.

    New Register.php file

    <?php bb_get_header(); ?>
    
    <div class="bbcrumb"><a href="<?php bb_uri(); ?>"><?php bb_option('name'); ?></a> » <?php _e('Register'); ?></div>
    
    <h2 id="register" role="main"><?php _e('Registration'); ?></h2>
    
    <?php if ( !bb_is_user_logged_in() ) : ?>
    
    <form method="post" action="<?php bb_uri('register.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_USER_FORMS); ?>">
    
    <fieldset>
    <legend><?php _e('Profile Information'); ?></legend>
    
    <p><?php _e("Your password will be emailed to the address you provide."); ?></p>
    
    <?php
    
    $user_login_error = $bb_register_error->get_error_message( 'user_login' );
    
    ?>
    
    <table width="100%">
    	<tr class="form-field form-required required<?php if ( $user_login_error ) echo ' form-invalid error'; ?>">
    		<th scope="row">
    			<label for="user_login"><?php _e('Username'); ?></label>
    			<?php if ( $user_login_error ) echo "<em>$user_login_error</em>"; ?>
    		</th>
    		<td>
    			<input name="user_login" type="text" id="user_login" size="30" maxlength="30" value="<?php echo $user_login; ?>" />
    		</td>
    	</tr>
    
    <?php
    
    $count='0'; // added here for a dirty fix to show only required fields
    
    if ( is_array($profile_info_keys) ) :
    	foreach ( $profile_info_keys as $key => $label ) :
    		$class = 'form-field';
    		if ( $label[0] ) {
    			$class .= ' form-required required';
    		}
    		if ( $profile_info_key_error = $bb_register_error->get_error_message( $key ) )
    			$class .= ' form-invalid error';
    
    ?>
    
    	<tr class="<?php echo $class; ?>">
    		<th scope="row">
    			<?php
    			if ( ++$count >= 2 )
    				continue;
    			?>
    			<label for="<?php echo $key; ?>"><?php echo $label[1]; ?></label>
    			<?php if ( $profile_info_key_error ) echo "<em>$profile_info_key_error</em>"; ?>
    		</th>
    		<td>
    		<?php
    
    		?>
    			<input name="<?php echo $key; ?>" type="text" id="<?php echo $key; ?>" size="30" maxlength="140" value="<?php echo $$key; ?>" />
    		</td>
    	</tr>
    
    <?php
    
    	endforeach; // profile_info_keys
    endif; // profile_info_keys
    
    ?>
    
    </table>
    
    <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p>
    
    </fieldset>
    
    <?php do_action('extra_profile_info', $user); ?>
    
    <p class="submit">
    	<input type="submit" name="Submit" value="<?php echo esc_attr__( 'Register »' ); ?>" />
    </p>
    
    </form>
    
    <?php else : ?>
    
    <p><?php _e('You’re already logged in, why do you need to register?'); ?></p>
    
    <?php endif; ?>
    
    <?php bb_get_footer(); ?>
    Posted 11 months ago #
  4. achtermijnpc
    Member

    I tested it, so far it works.

    Thanks.

    Posted 11 months ago #
  5. achtermijnpc
    Member

    Okay. More feedback here.

    In my template, the register button didn’t show up, using your code.

    I used a software called Compare It, to compare two files. I did that, and I saw that you were using » instead of &raquo; so I changed that, and also I changed You’re into You’re.

    So I think now the page is working, and the register button is showing.

    I noticed that this hack, just makes some fields invisible in the register.php page. A quick fix, like you said, perhaps in the future, this can be released as a plugin.

    Posted 11 months ago #
  6. Here take a look at the lines, I added in the register.php
    http://pastebin.com/f514d5ca9
    The code used was from Kakumei theme.

    I noticed that this hack, just makes some fields invisible in the register.php page

    What do ya mean? I just didn't let the php code produce html code.

    Posted 11 months ago #
  7. achtermijnpc
    Member

    Well actually the fields are being generated, their just empty. Just browse to my forum, to the sign up page, and check the code using Firebug. http://www.metalsuriname.com

    Posted 11 months ago #
  8. Only blank table cells are generated, not the code for input fields. Anyways I told you that its a quick dirty fix. It should be done with a semantic approach like having the allowed keys in an array and only display further if the $key is in array.

    Posted 11 months ago #
  9. Ok! Here is how you can avoid those empty table cells.
    http://pastebin.com/f6813e2c3

    Posted 11 months ago #
  10. achtermijnpc
    Member

    So you changed

    <?php
    if ( ++$count >= 2 )
         continue;
    ?>

    into

    if ( ++$count >= 2 )
         continue;

    That's all?

    Posted 11 months ago #
  11. Nope I changed its position. Moved it out of the table code so that even table cells are not created if we are by-passing the rest of the loop

    Posted 11 months ago #
  12. achtermijnpc
    Member

    OK. Just downloaded/uploaded this file, now I think it works the way it should.

    This calls for a drink.

    Posted 11 months ago #

Reply

You must log in to post.