Alright! Here we go. I've tried to abstract away most of the details so you can just drop it into your own form with only a few minor changes. Not sure if it'll work precisely as planned, but let's give it a go.
What you need to do is add a new login form, say "login.php". This should contain the following - obviously you can separate the PHP and HTML if - I just stuck it a single file for this example for convenience.
The idea is that all users going to your form will be faced with a login form off the bat. New users who haven't registered yet can use the default password (usually I just display it on the page). Existing users can log in with their own password - which they would have changed on page 1 of your own form.
Well, code first. Explanation below:
PHP Code:
<?php
$folder = dirname(__FILE__);
require_once("$folder/../admin/global/api/api.php");
ft_api_start_sessions();
$form_id = 53;
$username_field = "attendee_email"; // the database column that's acting as your "username" field.
$password_field = "password"; // the database column acting as your "password" field
$default_password = "pass123"; // our default password. This allows anyone to register using this password, which they can change during the reg process
$email = "";
if (isset($_POST["email"]) && !empty($_POST["email"]))
{
$email = ft_sanitize($_POST["email"]);
$password = ft_sanitize($_POST["password"]);
// try to locate the user
$query = mysql_query("
SELECT *
FROM {$g_table_prefix}form_{$form_id}
WHERE $username_field = '$email' AND
$password_field = '$password'
");
$result = mysql_fetch_assoc($query);
if (empty($result))
{
if ($password != $default_password)
{
$g_success = false;
$g_message = "Sorry, we couldn't locate that email/password combination. Please try again.";
}
else
{
// this is a new registrant" create a record for them
if (empty($result))
{
$default_values = array(
"attendee_status" => "Incomplete",
"$username_field" => $email,
"$password_field" => $default_password
);
$result["submission_id"] = ft_api_create_blank_submission($form_id, true, $default_values);
}
$_SESSION["form_tools_form"] = $result;
$_SESSION["form_tools_form"][$username_field] = $email;
$_SESSION["form_tools_form"]["attendee_status"] = "Incomplete"; // sets the form field "attendee_status" as
$_SESSION["form_tools_form"]["form_tools_form_id"] = $form_id;
$_SESSION["form_tools_form"][$password_field] = $default_password;
$_SESSION["form_tools_form"]["form_tools_submission_id"] = $result["submission_id"];
header("location: step1.php");
exit;
}
}
else
{
$_SESSION["form_tools_form"] = $result;
$_SESSION["form_tools_form"][$username_field] = $email;
$_SESSION["form_tools_form"]["form_tools_form_id"] = $form_id;
$_SESSION["form_tools_form"]["form_tools_submission_id"] = $result["submission_id"];
header("location: step1.php");
exit;
}
}
?>
<html>
<head>
</head>
<body>
<h1>Log In</h1>
<?php
if ($g_message) echo $g_message;
?>
<form method="post" action="<?=$_SERVER["PHP_SELF"]?>" name="login">
<div class="" style="padding-top: 3px; width:400px">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="120" class="blue">Email:</td>
<td><input type="text" size="25" name="email" id="email" value="<?=$email?>" tabindex="1" /></td>
<td width="80" align="center" rowspan="2">
<input type="submit" value="LOG IN" tabindex="3" />
</td>
</tr>
<tr>
<td class="blue">Password</td>
<td><input type="password" size="25" name="password" value="" tabindex="2" autocomplete="no" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
1. Update this line to point to your own api.php location:
require_once("$folder/../admin/global/api/api.php");
2. Set the $form_id to your own form ID.
3. Change these three fields to store the database column names of the fields that are going to act as the user's login username and password. In order to uniquely identify the user for when they log back in, these two are required. I always use "email" as a username field - simplest that way.
$username_field = "attendee_email";
$password_field = "password";
Also: I'm pretty sure the code requires your form fields to have the same database column names. I.e. your email field has a name attribute of "attendee_email" AND your database column for that field has the same value. I've always done this - had a 1-1 relation between form field names and database column names. It just makes working with the database that much simpler. You don't HAVE to do this, but you may have to review the code to ensure it's all okay.
4. The default password. The form I was taking this from required a default password for all new users to log in with. Once they were logged in, they could change it. If you don't need this feature, just change it to some long, indecipherable string.
$default_password = "pass123";
5. Change these lines to specify the first page in your form (there are two lines like this):
header("location: step1.php")
6. On the first page of your form you'll need to add the option to change the default password. All this requires is adding a field to your Form Tools form with the name attribute the same as specified above. And secondly, you'll need to add it to Form Tools so the information is actually stored in the database.
And I think that's it... Hope this is somewhat helpful & not too unclear.