FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
Info
FORMfields & FORMgen :: Generated Forms

Saving a User ID With Your Form Data

(2424 views. Last Updated: 2007-09-12 5:33 PM)

Here is an example of how to store a User ID with your from data. This example uses a session to store the User ID. In the following example, the user visits login.php and then is automatically logged in with a user_id of 7 and then forwarded to myform.php. When they complete myform.php the user_id of 7 is stored with their database data.

1. Use FORMgen to create a new IntegerField (doesn't matter where in the form) with Name: user_id, Label: User ID, Required: Required, Max Length: 10, Min Length: 1, Max Value: 9999999, Min Value: 1. If you are using FORMgen Lite, you will then need to run the create_my_table.php script created on Step 6.
2. This step is not required and is only for advanced users who wish to speed up database performance: use phpMyAdmin to create an index on user_id.
3. Edit your form and replace:
$ffForm->addField(new IntegerField("user_id", "User ID", FORM_FIELD_REQUIRED, 10, 1, null, 9999999, 1));
with:
//$ffForm->addField(new IntegerField("user_id", "User ID", FORM_FIELD_REQUIRED, 10, 1, null, 9999999, 1));
4. Edit your form and replace:
$ffForm->formFields["ff_inserted_on"]->getCurrentDateTime();
$ffForm->insertValuesIntoDb(FF_FORM_NAME);
with:
$ffForm->formFields["ff_inserted_on"]->getCurrentDateTime();

$ffForm->addField(new FormField("user_id", null));
if (!isset($_SESSION))
    session_start();
$ffForm->setValue("user_id", $_SESSION["user_id"]);

$ffForm->insertValuesIntoDb(FF_FORM_NAME);
5. Create or modify your login page to populate $_SESSION["user_id"]. Here is a dummy login page that you can use for testing:
login.php:
<?php

    
if (!isset($_SESSION))
        
session_start();

    
$_SESSION["user_id"] = 7;
    
    
header("Location: myform.php");

?>

For a slightly more advanced example that also shows how to retrieve data using a User ID, please see: http://www.formfields.com/support/viewPosting.php?pi=42
Info
Support | Earn Money
Copyright © 2005-2019 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.