Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Data handling  /  SetValue

SetValue
SetValue (
string $field
string $value
boolean $overwriteCurrentValue = false 
)

Arguments:

Name Description
$field The field where you want to set a value in
$value The value you want to set
$overwriteCurrentValue Should a posted value or a value from the database also been overwritten?

Description:

This function works on all fields! Needs to be placed before the field in order to keep the altered value in a multipage form!

In fields which can have multiple values (like a listfield), you can select multiple items in two ways:

  1. Give an array

  2. Give the items seperated with a comma (,)

See example 2 how to do this.

Example

<?php

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

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

// set a default value
$form -> setValue("name""Enter your name...");

// textfield
$form -> textField("Name""name"FH_STRING);

// button
$form -> submitButton();

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

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

// the 'commit after form' function
function doRun$data 
{
    return 
"Hello "$data["name"];
}

?>


The result is:
resizeIMG


Example 2: Setting more then 1 value
<?php

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

// options to use in the listfield
$options = array(
  
=> "option 1",
  
=> "option 2",
  
=> "option 3"
);

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

// listfield
$form -> listField("Options""options"$optionsFH_NOT_EMPTYtrue);

// set a default value
// (We have to set the index of the array,
// because we have set the option useArrayKeyAsValue to true.
// If we had not done that, we had to set
// the real "value" of the options array)
$form -> setValue"options""1, 3" );

// This was also correct!!
// $form -> setValue( "options", array(1, 3) );

// button
$form -> submitButton();

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

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

// the 'commit after form' function
function doRun$data 
{
    global 
$options;

    
$msg "Selected: \n";

    
// show the selected options
    
foreach($data['options'] as $id
    {
        
$msg .= " - ".$options[$id]." \n";
    }

    return 
$msg;
}

?>

Preview image

preview image

Latest change: 05 March 10 / 08:52

Comments

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