Quick Tip: Making a Fancy WordPress Register Form from Scratch

Quick Tip: Making a Fancy WordPress Register Form from Scratch

Tutorial Details
  • Difficulty: Intermediate
  • Estimated Completion Time: 30 min

In this tutorial, I will guide you through the process of making a beautiful “Register” form, using Fancybox, jQuery, and, of course, WordPress. As you’ll find, the process is really quite simple.

Step 1. The Markup

First, let’s place our button at the top of the page, replacing the default description in the theme.

<div id="registration"><a class="show register-button" href="#register-form">Register</a></div>

Notice that in the register button, the href (#register-form) is the same ID as the form below. We’re also using the class “.show” to call FancyBox with jQuery.

We need our base; let’s create our markup. Open header.php, and place this following snippet anywhere you’d like.

<div style="display:none"> <!-- Registration -->
		<div id="register-form">
		<div class="title">
			<h1>Register your Account</h1>
			<span>Sign Up with us and Enjoy!</span>
		</div>
			<form action="" method="post">
			<input type="text" name="" value="Username" id="" class="input"/>
			<input type="text" name="" value="E-Mail" id="" class="input" />
				<input type="submit" value="Register" id="register" />
			<hr />
			<p class="statement">A password will be e-mailed to you.</p>
			</form>
		</div>
</div><!-- /Registration -->

Note that I’m using display:none to hide the form initially.


Step 2. CSS

The CSS is rather simple; I’m merely styling a quick form design in PhotoShop.

The form, minus the styling, looks like so: (note that I’ve removed the display:none in the markup to check my styles)

Let’s next begin styling our box.

div#register-form {
	width: 400px;
	overflow: hidden;
	height: 230px;
	position: relative;
	background: #f9f9f9 url(images/secure.png) no-repeat 260px 40px;
	font-family: Helvetica Neue, Helvetica, Arial !important;
}

Continuing on, I’ll now style the text inputs, adding some fanciness.

div#register-form input[type="text"] {
	display: block;
	border: 1px solid #ccc;
	margin: 5px 20px;
	padding: 9px 4px;
	-moz-border-radius: 4px;
	-webkit-border-radius:4px;
	width: 200px;
	font-family: Helvetica Neue, Helvetica, Arial !important;
}

div#register-form input[type="text"]:hover {
	border-color: #b1b1b1;
}

div#register-form input[type="text"]:focus {
	-moz-box-shadow: 0 0 3px #ccc;
	-webkit-box-shadow: 0 0 3px #ccc;
}

Now, I’ll style the button, adding a hover state, and replacing the default button with an image.

div#register-form input[type="submit"]#register {
	background: url(images/register.jpg) no-repeat;
	border: 0;
	clear: both;
	cursor: pointer;
	height: 31px;
	overflow: hidden;
	position: relative;
	left:295px;
	text-indent: -9999px;
	top:42px;
	width:92px;
}
div#register-form input[type="submit"]#register:hover {
	background-position: 0 -32px;
}

Finally, we add some general styling.

div#register-form span {
	display: block;
	margin-bottom: 22px;
}

div#register-form div.title {margin-left:15px}
div#register-form div.title h1,
div#register-form div.title span {text-shadow:1px 1px 0px #fff}
div#register-form div.title h1 {
	margin:7px 0;
}

p.statement {
	position:absolute;
	bottom:-2px;
	left:10px;
	font-size:.9em;
	color:#6d6d6d;
	text-shadow:1px 1px 0px #fff;
}

Voila! we have our form. Now, let’s move forward with the jQuery functionality.


Step 3. jQuery

First, we need to include jQuery within WordPress. To achieve this, we need to place the following chunk of code before the <head> tag within the header.php file. Remember, as WordPress itself utilizes jQuery, we don’t want to potentially load it twice!

<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>

Download Fancybox and place it in your WordPress folder. To organize things a bit more, I’ve created an “Includes” folder.

Next, open your footer.php file, and place the following before the end of the </body> tag

<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/includes/fancybox/jquery.fancybox-1.3.1.css" media="screen" />
	<!-- Javascript -->
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/includes/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/includes/fancybox/jquery.fancybox-1.3.1.pack.js"></script>

And now, let’s call the fancybox method; paste this after the code above and before the closing body tag.

		jQuery(document).ready(function() {
			jQuery(".show").fancybox({
				'titleShow'		: 'false',
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade'
			});
		});

We’re done! Our form has been created; we lastly just need to pass the necessary WordPress information to make it function properly.


Step 4. WordPress

There is nothing fancy here; we only require two WordPress snippets, hidden within the wp-login.php file.

The first snippet:

<?php echo site_url('wp-login.php?action=register', 'login_post') ?>

And:

<?php do_action('register_form'); ?>

The final code should look like so:

<div style="display:none"> <!-- Registration -->
		<div id="register-form">
		<div class="title">
			<h1>Register your Account</h1>
			<span>Sign Up with us and Enjoy!</span>
		</div>
			<form action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
			<input type="text" name="user_login" value="Username" id="user_login" class="input" />
			<input type="text" name="user_email" value="E-Mail" id="user_email" class="input"  />
				<?php do_action('register_form'); ?>
				<input type="submit" value="Register" id="register" />
			<hr />
			<p class="statement">A password will be e-mailed to you.</p>

			</form>
		</div>
</div><!-- /Registration -->

Please note that it’s really important, and necessary, to have user_login as a name and as an ID in your text input; the same is true for the email input. Otherwise, it won’t work.

And with that, we’re done!

Conclusion

With a touch of code, and some tweaks, we’ve managed to build a great looking “Register Form” for our users. What do you think?

Add Comment

Discussion 86 Comments

Comment Page 1 of 21 2
  1. Pieter V says:

    Great tutorial, keep the wordpress ones coming!

  2. yoshz says:

    Thanks for this tip. very useful :)

  3. esranull says:

    very nice post thanks a lot

  4. amidude says:

    Nice tut…isn’t having style=”display:none” inside your markup bad coding? Can’t that be placed in the stylesheet?

  5. Daniel Ribeiro says:

    Great!

    Another great post!

    Congratulations from Brazil!

  6. Davidmoreen says:

    This was a pretty nice tutorial for a Quick Tip! I love the fancy box integration!

  7. Frenky says:

    Wow, what a new. I’m going to use that.

    Thanks to author. ;)

  8. Xcellence IT says:

    awesome tutorial….

    Thanks for sharing this…

    Regards
    Xcellence IT

  9. Don says:

    That’s great!
    Thanks heaps.

  10. Wai Han says:

    What a nice tutorial! Thanks for sharing.

  11. AlchemyCode says:

    Great article! I always appreciate wordpress tutorials :)

  12. Codeforest says:

    I really like tutorials like this. WordPress is great. Keep it coming

  13. Nice stuff…I was always thinking how to implement a “Register” feature on the wordpress blog. There are many plugins available for that but nothing beats a completely customized coded registration box :) Thanks for sharing…!

  14. Drazen Mokic says:

    Man…” ” Inline CSS? Why?

    I like the result but the totally unnecessary use of inline css is really ugly.

    • Drazen Mokic says:

      And btw, without javascript no registration right? Adding “display:none” with Javascript would have been a better idea (progressive enhancement).

      I dont want to play the bad guy but that`s a serious point.

  15. You correctly used wp_enqueue_script to load jquery. For consistency, you should probably also use it for the FancyBox scripts, even though they are in your theme directory.

  16. Excellent tutorial for WordPress, thanks for the contribution.

  17. HDesignsPlus says:

    Thanks Ivor Padilla, Just what I needed, although I expected an screen cast for this quick tip, but even without a video it was very helpful, all i found on the web about this was just some outdated tuts, but this one is fresh out of the oven :)

  18. James says:

    Can we do the same thing with login?

    • Ronald says:

      I was also looking to do this, and, seeing as no one else had, I tinkered around with it myself until I had transformed it into a Login feature.

      Just replace the “form” part of the code with the following:

      <form action=”<?php echo site_url(‘wp-login.php’, ‘login’) ?>” method=”post”>
      <input type=”text” name=”log” value=”Username” id=”user_login” class=”input” />
      <input type=”password” name=”pwd” value=”" id=”user_password” class=”input” />
      <?php do_action(‘login_form’); ?>
      <input type=”submit” value=”Login” id=”login” />
      </form>

  19. SkipSoft says:

    WoW, Really Nice Tutorial. Thanks.

  20. thank! very useful

  21. dellopos says:

    Thanx. Very nice.

  22. 5-Squared says:

    Awesome post Ivor! Thanks!

  23. Sylvie says:

    Thanks Ivor awesome tutorial.

  24. aaslin says:

    good guide for wordpress…give more of wordpress

  25. Martin says:

    This is another incomplete WORDPRESS tutorial.

    I think I have gone through 10-12 of these wordpress tutorials only to find the author rushes to the end and seems to leave out one of the most important pieces of information; That is how and where to place the snippet of code in WORDPress.

    This mostly occurs in the wordpress plugin tutorials.

    Come on TUTS.

    Quality Control for my Bucks.

  26. Cesar says:

    Excellent tutorial. I have been looking for this information all around, and I could not find it. Thanks !!

    Could you please indicate a way to re-direct the user after the “register” button has been clicked to a page, instead to go to the wp-login.php?

    Best,

  27. Ejaz says:

    Great tip Ivor, Let me add my two cents

    div should not be appended before an ID, it makes it slower and overly qualified. This is a performance drawback.
    (more info http://code.google.com/speed/page-speed/docs/rendering.html#UseEfficientCSSSelectors)

    e.g.
    div#register-form span {
    should be

    #register-form span {

    I hope this would make already good code a better one.

  28. Yomero says:

    Yeah, I’m interested in knowing that. Also, what hooks do I need to use to make a Register form? Really, thanks for the info!

  29. Grant says:

    Thanks, that is a good register way for me to use.

  30. Gavin says:

    Hey thanks for the tip – it’s really going to help me out. I need a little help though – I have tried to implement the custom registration box but fancybox just won’t play. Obviously it’s not working as in my footer I’m getting this text displaying:

    jQuery(document).ready(function() { jQuery(“.show”).fancybox({ titleShow’: ‘false’, ‘transitionIn’: ‘fade’, ‘transitionOut’: ‘fade’}); });

    Why does that code belong in the footer – can someone please explain that to me. I have tried change file premissions thinking it might be that but no luck.

    Any help would be much appreciated

    Thanks

  31. Jaysone says:

    Wish there was a post on wordpress comments. Getting it setup especially with the fact that wordpress 3.0 is out.

  32. imran14826 says:

    Could you please indicate a way to re-direct the user after the “register” button has been clicked to a page, instead to go to the wp-login.php?

    Imran14826
    http://www.livetv.pk

  33. Federico says:

    Could anybody explain me more in detail the 4th step?

    Where to put the wordpress code snippet?

    Thanks and sorry for my english

  34. Ali says:

    Hi,

    Thanks for the code but can some guide me how to autoload this registration box on page load. I’ve tried to use the onload click event but nothing happens.

    Thanks,
    Ali

  35. Donnie says:

    PLEASE PLEASE PLEASE could you show how it is done to redirect back to the page with the message instead of directing to the login.php. PLEASE ^^

  36. erna says:

    nice!
    just the way I want!
    simple and easy.

  37. daists says:

    very nice ~!

    Thanks your share ~!

  38. pop says:

    thanks man….

    was really a great help…

    n a great tutorial too..

  39. Works here!
    But how I do proceed to choose the size of lightbox content?
    Width and height?

    thanks from Brazil!

  40. clickddl says:

    very goood site. thanx.

  41. nice post. it’s very usefull

  42. Art Eppley says:

    Very nice “quick Tip” however, the reg box does not show… I don’t get the same “issues” as having the jquery in the footer show (i knew to add the to both sides….why isn’t this appearing????

  43. jim says:

    beautifull… thanks for share…

  44. dan says:

    im using prettyphoto in my wp site and fancybox conflicts,can i use the pretty photoin its place and how would i implement it,

    any help is appreciated

  45. Marz says:

    This is a great tutorial, but what if you want to use this as a “Log In” and not for “Registration”?

    What PHP code should apply in order to change the box into “Log In” box?

  46. Postern says:

    Thank you very much for this,It saved my time
    really thrilling to use it

  47. Ryan says:

    Anyone know how this can be accomplished with the WordPress Thesis 1.8, and openhooks?

    You need to edit the custom.css files, and prefix everything your styling with .custom, and you must add everything in openhooks, so its slightly varied.

    If anyone has accomplished this same thing with thesis and openhooks i’d really like to hear from them

  48. Rudy Pohl says:

    Hi Ivor:

    I’ve read through the entire tutorial and am looking forward to working through it this Saturday when I finally have some time.

    One question: Are yuo familiar with the Genesis Framework for WordPress, and if you are, do you know if your method above will work on their themes?

    Thanks again…. great teaching!

    Rudy in Ottawa

Comment Page 1 of 21 2

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.