Forum Moderators: coopster

Message Too Old, No Replies

Dynamic Form

         

derenw

11:20 am on Apr 2, 2004 (gmt 0)

10+ Year Member



Hi all,

I have one user table in my MySQL database and this is linked to a user type table containing 3 types of user. Each type of user will be required to give a different amount of data when registering.

Basically I want to create one registration form for all types of users but only show the form fields that are relevant to the individual user type. The user type will be selected from a pervious page containing a list menu with the 3 user types that is sent via GET to the registration page.

I am guessing that I will have to use if startments but amnot sure how to do it.

Any help would be great!

Thanks

Birdman

12:20 pm on Apr 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you get to a form field that may or may not be displayed, run an if statement.

if($_GET["user_type"] == 1){
print "form field here";
}

Alternatively, create three separate forms(just the form) and save them as .txt, .html or .php(if they will contain php code). On the main form page, right at the point where the form code should start, run a switch statement and include the proper form.

<html><body>
<?php
switch($_GET["user_type"]){
case 1: include($_SERVER["DOCUMENT_ROOT"]."path/to/form1.txt);
break;
case 2: include($_SERVER["DOCUMENT_ROOT"]."path/to/form2.txt);
break;
case 3: include($_SERVER["DOCUMENT_ROOT"]."path/to/form3.txt);
break;
default: header("Location: /pickusertype.php"); //no user type chosen(redirect)
}
?>

andylarks

12:50 pm on Apr 2, 2004 (gmt 0)

10+ Year Member



nice comprehensive answer Birdman :)