Login Retreive lost passwordRegister
Search

Manual  /  Functions  /  Look & Feel  /  SetMask

SetMask
SetMask (
string $mask = null,
mixed $repeat = true 
)

Arguments:

Name Description
$mask The mask which you want to use for the oncomming fields. When no mask is given, the default mask is used (set in the config file with the var FH_DEFAULT_ROW_MASK).
$repeat Should the mask be repeated? When set to true (default), the mask will be repeated unlimited. When a integer is used, the integer will be countdown and the mask will be displayed as long as the number is greater then 0. After this the mask will be set back to the default mask.

Description:

With this function you can change to look of your form. Default, the form is set in a table. FormHandler sets each field in a seperate row. The default mask (can be edited in the config file!):

  <tr>
    <td valign='top'>%title%</td>
    <td valign='top'>%seperator%</td>
    <td valign='top'>%field% %help% %error%</td>
  </tr>


As shown above, you have to set some special "words" which are replaced with the real value:

  • %title% - Is replaced with the title of the field (the first argument of all fields)

  • %seperator% - Is replaced with a ":". When no title is given, no seperator is placed.

  • %field%- Is replaced with the field OR BUTTON!

  • %error% - Is replaced with a possible error message when the field was invalid. When there is no error message, it will just be removed.

  • %name% - Is replaced with the name of the field or button

  • %value% - Is replaced with the value of the field

  • %help% - Is replaced with a help icon. See for more information at setHelpText

  • %error_style%
  • - element with this "word" will get the error class added to any existing classes


When using a template file it's also possible to use

  • %header%
  • - is replaced with the start of the form ie <form> tag
  • %footer%
  • - is replaced with the end of the form ie </form> tag


The mask is repeated untill all the fields are processed. However, you can change this. If wanted, you could set 2 or more fields in one row and use this "layout" untill all fields are processed. It is even possible to fill one mask with all the %field% signs, so that you can use templates. How to do this is explained below.

Note: When the mask is not completly filled but all the fields are processed, the remaining %field% tags and so are removed from your mask!

Example

<?php 

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

// create new formhandler object 
$form = new FormHandler(); 

// set another type of mask 
$form -> setMask
  
"  <tr><td>%title% %seperator%</td></tr>\n"
  
"  <tr><td>%field% %error%</td></tr>\n"
  
true  # repeat this mask! 
); 

// some fields 
$form -> textField("Name""name"FH_STRING); 
$form -> textField("Age""age"FH_INTEGER32); 
$form -> selectField("Gender""gender", array('M''F'), nullfalse); 

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

// data handling 
$form -> onCorrect("doRun"); 

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

// data handler 
function doRun$data 

    
// do something here! 
    
echo "Data recieved!"

?>


The result:
resizeIMG

Some HTML code of the result (example of the mask!):
resizeIMG


Example 2: Using a template
Since FH3 v1.2.2 It is also possibnle to use a php file as a template the file will be parsed!
<?php

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

// create new formhandler object
$form =& new FormHandler();

// set the template we are using
$form -> setMask
  
'templates/form.tpl'
  
false # dont repeat this mask
);

// Let formhandler don't use the <table> tag 
$form -> useTablefalse ); 

// some fields
$form -> textField("Name""name"FH_STRING);
$form -> textField("Age""age"FH_INTEGER32);
$form -> selectField("Gender""gender", array('M''F'), nullfalse);

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

// data handling
$form -> onCorrect("doRun");

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

// data handler
function doRun$data 
{
    
// do something here!
    
echo "Data recieved!";
}
?>


The result:
resizeIMG

The template used above contains html code:
resizeIMG

See also: UseTable

Latest change: 05 March 10 / 08:44

Comments

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