Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Fields  /  PassField

PassField
PassField (
string $title
string $name
mixed $validator = null,
integer $size = 20,
integer $maxlength = null,
string $extra = null 
)

Arguments:

Name Description
$title Title of the field
$name Name of the field
$validator This can either be the name of your own validation function or the constant name of a predefined validator function. For more information about validators see Validators.
It is also possible to use a method as a validation function. In this case you should pass an array where the first item is the object and the second item the name of the method.
$size The size of the field.
$maxlength The maximum allowed characters in this field. 0 is interpretated as no limit.
$extra This can be extra information which will be included in the fields html tag. You can add for example some CSS or javascript.

Description:

Creates a passfield on the form.

The value of the field is never filled into the field, so the password is never vissible in the source code of the page. When the database option is used and the form is in edit mode, the password will not be saved when no value is given (so the original is kept)

Example

<?php

// include the class
include('FH3/class.FormHandler.php');

// make a new $form object
$form = new FormHandler();

// a textfield
$form -> passField("Your password""pass"FH_PASSWORD);

// submitbutton beneath it
$form -> submitButton("Save");

// set the 'commit after form' function
$form -> onCorrect("doRun");

// send the form to the screen
$form -> flush();

// function to show a message
function doRun($data
{
    return 
"Your password is: "$data["password"];
}
?>


Here is an example with password's check and saving the password encrypted into the database:

<?php

// include the database formhandler class
include("FH3/class.dbFormHandler.php");

// create new dbFormHandler object
$form = new dbFormHandler();

// set the database connection info
$form -> dbInfo"myDatabase""myTable" );
$form -> dbConnect"myHost""myUsername""myPassword" );

// create the two password fields
$form -> passField"Password""myPass" ); 
$form -> passField"Retype password""myPass_re" ); 

// check the password fields. 
// See for more info about this function the manual
$form -> checkPassword"myPass""myPass_re" ); 

// Only save the value when it's an insert form 
// and when a value is given
if( !$form -> edit || $form -> value("myPass") != '' 

    
// now save the value encrypted!
    
$form->addValue("myPass"md5$form->value("myPass") ) ); 


// button to submit the form
$form -> submitButton();

// what to do when the form is saved ?
$form -> onSaved"doSomething" );

// show the form
$form -> flush();

// this is the function which is called after the data is saved into
// the database.
function doSomething$id$data )
{
    echo 
"The data is saved!";
}
?>

See also: CheckPassword

Latest change: 05 March 10 / 08:31

Comments

powered by PHP-GLOBE   © 2004 - 2024 FormHandler. All rights reserved.   -   Open source license