Login Retreive lost passwordRegister
Search

FAQ (Frequently Asked Questions)



Can I place the fields in 2 seperate columns ? top
Yes, this is possible. You can do this in 2 ways.

First you can set a different mask which sets multiple cells, like this:

<?php

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

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

// set a new mask
$form->setMask(
  
"  <tr>\n".
  
"    <td>%title%</td>\n".
  
"    <td>%seperator%</td>\n".
  
"    <td>%field% %error%</td>\n".
  
"    <td>&nbsp;&nbsp;</td>\n".
  
"    <td>%title%</td>\n".
  
"    <td>%seperator%</td>\n".
  
"    <td>%field% %error%</td>\n".
  
"  </tr>\n",
  
true # repeat this mask!
);

// ... here your fields ...
?>


Second, you can use the function AddHTML to change the table layout of the form. Notice that formhandler default puts the fields in table rows:
<?php

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

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

// create first column of fields
$form->addHTML(
    
"  <tr>\n".
    
"    <td>\n".   
    
"     <table align='center' width='100%' border='0'>\n".
    
"       <tr valign='top'>\n".
    
"         <td>\n".
    
"           <!-- Fields in the left column -->\n".
    
"           <table>\n"
);

// some example fields in the left column
$form->textField("Name""name"FH_STRING2050);
$form->textField("Age""age"FH_INTEGER22);

// start from here the right column
$form->addHTML(
    
"           </table>\n".
    
"         </td>\n".
    
"         <td valign='top'>\n".
    
"           <!-- Fields in the right column -->\n".
    
"           <table>\n"
);

// some example fields in the right column
$form->selectField("Gender""gender", array('M','F'), ''false);
$form->radioButton("Internet connection""internet", array('Fast''Slow'), FH_NOT_EMPTY0);

// end of the right column
$form->addHTML(
  
"           </table>\n".
  
"         </td>\n".
  
"       </tr>\n".
  
"      </table>\n".
  
"    </td>\n".
  
"  </tr>\n"
);

// to set the submitbutton in the center of the form...
$form->setMask(
  
"  <tr>\n".
  
"    <td align='center'>\n".
  
"      %field%\n".
  
"    </td>\n".
  
"  </tr>\n",
  
false # do not repeat this mask
);  

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

// set the data handler
$form->onCorrect('doRun');

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

// the data handler
function doRun$data ) {
    
// do something here...
    
echo "<pre>\n";
    
print_r$data );
    echo 
"</pre>\n";
}

?>

Can I remove the line "This form is generated by FormHandler" top
Yes, you can. Only we ask you to please let it be as it is. We have put many hours into this project to make it as good as it is. We offer you a good product completly free! To make this project grow, we need visitors and more users. So by putting this line at the bottom of the form we can continue building FormHandler and keep it FREE!

If you still want to remove the line, would you like to link us instead?

You can remove the line by setting the configuration var FH_EXPOSE to false, or use this:
<?php

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

// disable the line
define'FH_EXPOSE'false );

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

// ...

?>

How can I clear the fields which are invalid? top
You can do that as shown in the example below:

<?php

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

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

// some textfields
$form->textField("Name""name"FH_STRING2050);  
$form->textField("Age""age"FH_INTEGER25);  

// check if the form is posted...
if( $form->isPosted() ) 
{  
    
// catch the errors but let formhandler still display them!
    
$errors $form->catchErrorstrue );

    
// walk each field (with an invalid value) and clear the data
    
foreach( $errors as $field => $err
    {
        
// set an empty value
        
$form->setValue($field""true);  
    }
}  

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

// set the handler
$form->onCorrect("doRun");  

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

// the data handler
function doRun$data 
{  
    echo 
"Hello "$data["name"];  
}  

?>

How can I make a selectfield with an "other" option? top
Since FH3 version 1.2.6 you can use the textSelectField to achieve that


You can do that with somehting like this:

<html>
<head>
<title>FormHandler: SelectField with "other" option</title>
<script language="javascript" type="text/javascript">

// function to show or hide the "other" field
// field: the object of the selectfield
// showOnValue: the value of the selectfield when the "other" field should be displayed
function showHideOtherField( field, showOnValue )
{
    // the name of the other field (same as the selectfield only with "_other" behind it)
    var name = field.name + "_other";

    // get the object of the "other" field
    if( document.getElementById )
    {
        var other = document.getElementById( name );
    }
    else if( document.all )
    {
        var other = document.all[ name ];
    }
    else
    {
        var other = null;
    }

    // did we got the object of the other field ?
    if( other )
    {
        // now, show or hide the field
        other.style.display = ( field.value == showOnValue) ? 'inline' : 'none';
    }
    // we could not retrieve the object of the other field..
    // display warning message
    else
    {
        alert(
          'Error, could not display the field for a user ' +
          'specific value. Please use a newer/better browser...'
        );
    }
}
</script>
</head>
<body>

<?php

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

$form = new FormHandler();

// the options array
$options = array(
  
=> 'Optie 1',
  
=> 'Optie 2',
  
=> 'Optie 3',
  
=> 'Other:'
);

// value when the "other" field should be displayed
$showOnValue 4;

// use other mask so that the other field will be displayed behind the selectfield
$form->setMask(
  
"  <tr>\n".
  
"    <td>%title%</td>\n".
  
"    <td>%seperator%</td>\n".
  
"    <td>%field% %field% %error% %error% %help% %help%</td>\n".
  
"  </tr>\n",
  
false
);

// the selectfield
$form->selectField'test''test'$options0101'onchange="showHideOtherField( this, \''.$showOnValue.'\' );"' );

// the "other" (default hidden)
$form->textField('''test_other'FH_STRING2050'style="display:none;"' );

// at this point we have to load the value of the other field
// manually when the form is posted
// NOTE: when using the database option you should also load the value
// of the field when it's a edit form! (add $form -> edit to the if statement )
if( $form->isPosted() )
{
    
// get the value of the selectfield;
    
$value $form->value('test');

    
// should we show the "other" field ?
    
if( $value == $showOnValue )
    {
        
// initialise the fields value... 
        // (should it be displayed or not on startup ?)
        
$form->addHTML(
          
"<script language='javascript' type='text/javascript'>\n".
          
"//initalise the field's value...\n".
          
"showHideOtherField( \n".
          
"  document.forms['".$form->getFormName()."'].elements['test'],\n".
          
"  '".$showOnValue."'\n".
          
");".
          
"</script>\n"
        
);
    }
}

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

// the handler function
$form->onCorrect('test');

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

// the funciton which is runned after the form is correct
function test$data )
{
    echo 
"<pre>";
    
print_r$data );
    echo 
"</pre>";
}
?>

I get a javascript error on the page! top
Probably the FH_FHTML_DIR config var is not pointing to the correct path. You can set this in the Config file.

If this is not the problem, please place a message in the forum!

Is it possible to encrypt a password before saving it? top
Yes, this is possible. Example:

<?php

// ...

$form->passField("Password""password"FH_PASSWORD);

// overwrite the current value
$form->addValue("password"md5$form->Value("password") ) );

// ..
?>


NOTE: If you use the function checkPassword, it's also possible for the users to leave the field blank (in an edit form). You have to make sure that you only encrypt the password when a password is submitted!!

Example:
<?php

$form 
= new FormHandler();

// ...

$form -> passField'Password''pwd1' );
$form -> passField'Retype password''pwd2' );
$form -> checkPassword'pwd1''pwd2' );

// check if a password is given
if( $form -> getValue'pwd1' ) != '' )
{
    
// save the password md5 encrypted
    
$form -> addValue'pwd1'md5$form -> getValue('pwd1') );
}

// ..

?>

The editor is not working! I am getting an empty frame! top
Probably the config var FH_FHTML_DIR is not pointing to the right directory. Make sure that this is a URL, relative or complete. So NOT a path!

If that does not solve the problem, please post a message in the forum.

When I hit the cancel button I get the error that the page is expired top
Yes, this can happen. You can aviod this by putting this line in the top of your document (before sending anything to de page):

<?
header
("Cache-control: private");
?>

When I submit my form, I get the error that the onCorrect or OnSaved function not exitst! top
Probably you have onCorrect or the onSaved function placed in an if structure or something like that. If so, you can resolve the porblem in two ways:

1. Put the function somewhere outside the if structure
2. Put the function above the creation of the FormHandler object

See the examples below:

This is wrong:
<?php

/* WRONG */
if( isset( $_GET['form'] ) ) 
{
    
// create simple form
    
$form =& FormHandler();
    
$form->textField('Test''test');
    
$form->submitButton();
    
$form->onCorrect('doRun');
    
$form->flush();

    function 
doRun($data
    {
        
// do something...
    
}
}
?>


This is the correct way:
<?php

/* CORRECT */
if( isset( $_GET['form'] ) ) 
{
    
// create simple form
    
$form =& FormHandler();
    
$form->textField('Test''test');
    
$form->submitButton();
    
$form->onCorrect('doRun');
    
$form->flush();
}

// place outside the if statement!
function doRun($data
{
    
// do something...
}
?>


This is also correct:
<?php

/* CORRECT */
if( isset( $_GET['form'] ) ) 
{
    
// place above the form object creation
    
function doRun($data
    {
        
// do something...
    
}

    
// create simple form
    
$form =& FormHandler();
    
$form->textField('Test''test');
    
$form->submitButton();
    
$form->onCorrect('doRun');
    
$form->flush();
}
?>

When I upload a file, I keep getting the message "The uploaded file is of an invalid file type!" top
When the extension of the file is allowed in the config's "type" string, the problem is propably a mime type which is not allowed. You can check if this is the problem by un-escaping a debug message in the file FH3/fields/class.UploadField.php. Go to +/- line 457. There you will find an escaped debug message. Unescape this and run your script again. Now you should be able to see what's going wrong... After retrieving the mime type of the file you can allow it by adding the mime type of the file in the config array.

If you can't get it working, please post a message in the forum!



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