PHPmotion: Adding fields to the sign up form

Here’s another little tutorial to show you how to add extra fields on the signup page. This is pretty straight forward but requires some changes to the database so proceed with caution!

Step 1: Add extra fields to the inner_signup_form.htm file:

Open your inner_signup_file.htm file and add an input field there are several which can be used for example:

Myfield :
<input name="myfield" value="[var.myfield]" type="text" />

Will display:

Myfield :

Of course myfield is whatever you want it to be :) Name, Age, Sex, etc…

Step 2: Adding the rows to the database member_profile table

This is the bit you want to be careful with, it’s not risky but clicking in the wrong place could give you undesired results!

As image are worth a million words (or something like that :) ) here’s some pics:

Once you’re in there you’ll have to create the rows:

Now add the name, etc…

Depending on what kind of data you’ll be entering you’ll have to choose the correct type, etc…

Now that’s done you’ll just have to make sure that everything gets sent to the database.
Step 3: Editing register.php

In register.php you’ll see this:

$form_submitted = $_POST['form_submitted'];//check if form has been submitted
$account_type = "standard";
$email_address = mysql_real_escape_string($_POST['email_address']);
$user_name = mysql_real_escape_string($_POST['user_name']);
$password = mysql_real_escape_string($_POST['password']);
$confirm_password = mysql_real_escape_string($_POST['confirm_password']);
$error_message = "";
$checked = "";
$procede = true;
$site_name = mysql_real_escape_string($config['site_name']);

Change it like so:

$form_submitted = $_POST['form_submitted'];//check if form has been submitted
$account_type = "standard";
$email_address = mysql_real_escape_string($_POST['email_address']);
$user_name = mysql_real_escape_string($_POST['user_name']);
$password = mysql_real_escape_string($_POST['password']);
$confirm_password = mysql_real_escape_string($_POST['confirm_password']);
$myfield = mysql_real_escape_string($_POST['myfield']); // This is the custom field
$error_message = "";
$checked = "";
$procede = true;
$site_name = mysql_real_escape_string($config['site_name']);

Find this bit of code:


    // insert new user record
    $sql = "INSERT into member_profile (user_name, password, email_address, account_status, account_type, date_created, random_code) VALUES ('$user_name', '$password', '$email_address', 'new', 'standard', '$date', '$random_code')";
    @mysql_query($sql) or die(@header("Location: " . "system_error.php?code=101"));

Change this like so:


    // insert new user record
    $sql = "INSERT into member_profile (user_name, password, email_address, account_status, account_type, date_created, random_code,myfield) VALUES ('$user_name', '$password', '$email_address', 'new', 'standard', '$date', '$random_code','$myfield')";
    @mysql_query($sql) or die(@header("Location: " . "system_error.php?code=101"));

There we go it should all be working now :) Just make sure that you stick to the same name throughout and you shouldn’t run into any problems :)


Don’t forget to check out my free installation offer: Free PHPmotion installation

3 thoughts on “PHPmotion: Adding fields to the sign up form

  1. The information will go to the database, after that you’ll have to add extra stuff to call the info in the other pages. I’ll write another tutorial to tell you how to do that if you need it :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>