JDT

 

FREE Downloads
Articles
Tutorials

 

Creating a Registration Form and Form Handler in PHP


It is often necessary to enable visitors to your website to register. This would then give them access, via a username and password, to various 'restricted' areas of your site. Quite often when users register, they set up their own username, and the website generates a password for them. They can then, if they wish, change their password. This type of user registration system requires no input from you, as the webmaster. If you need to enable users to set up their own web pages on your site, or have unique access to an application on your site, this is typically the type of user registration system you would use.

Alternatively, you might want to implement a system whereby the user fills in a registration form, which then generates an email that is sent to you. You can then decide whether or not you want to allow the person to register. If you do let them register, you would then email them a username and password that they could use to access the restricted areas of the site. You would typically use this type of user registration system when users do not require unique access to the restricted areas of your site, for example, access to price lists or other generic information that is only available to registered users.

In this tutorial we will look at how to create a user registration system that generates an email that is automatically sent to an email address.

File 1 - form.htm


<html>
<head>
</head>
<body>
<form name="form" method="post" action="sendEmail.php">
<p>Name: <input type="text" name="name" size="40"></p>
<p>Email: <input type="text" name="fromEmail" size="40"></p>
<p><input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset Form"></p>
</form>
</body>
</html>

This first file, form.htm, is a very simple form that prompts the visitor to enter a name and email address. On a real registration form you would almost certainly request more information than this.

When the submit button is clicked, the form data is passed to file 2, sendEmail.php.

File 2 - sendEmail.php


<?php

$name=$_REQUEST['name'];
$fromEmail=$_REQUEST['fromEmail'];

// Send email to the following address
$email = "fred.bloggs@somewhere.co.uk";

// The subject
$subject = "A sample form";

// The message
$message = "Name: $name\n\n".
"Email: $fromEmail";

mail($email, $subject, $message, "From: $fromEmail");

?>

<html>
<head></head>
<body>
<p>Thank you for your registration request.</p>
</body>
</html>

File 2, sendEmail.php, processes the data entered in the form, generating an email that is sent to fred.bloggs@somewhere.co.uk. It also displays a message on the screen thanking the user for their registration request.


Author: Backrubber
John Dixon Technology Ltd







Go back to PHP Tutorials home page

Go back to Tutorials home page



Need a FREE bookkeeping package?

Why not try Earnings Tracker? John Dixon Technology's free accounting / bookkeeping software tool.

Need free accounting software
 



JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions