Login Retreive lost passwordRegister
Search

Forum Index / General / How to add conditional form elements?

[ This topic is solved ]

  Babak Fakhamzadeh 15 January 12 / 21:02  
Is it possible to include conditional form elements? That is, require different fields to be filled in based on the answer of another field.

For example, a form can contain a question "How many children do you have?", allowing for answers that are "0", "1", "2", "More than 2". Then, if the user selects anything but "0", the form requires the user to fill in the field "Give the name of the oldest child".
Ideally, the second question should only show up after the first question was answered.

Can this be implemented with the current FormHandler?

  Johan Wiegel (Admin) 16 January 12 / 12:52  
This cannot be done directly with FH.

But you can use javascript to enable and disable parts of your page and use an conditinal validator in FH.

<?php
if( $oForm->getValuefield1 ) > )
{
    
$validator 'FH_NOT_EMPTY';
}
else
{
    
$validator null,
}
$oForm->TextField'label''name'$validator );
?>

  Babak Fakhamzadeh 16 January 12 / 14:20  
I'm not clear on what you're doing there. Using a conditional validator like you suggest is only relevant for when the form is being edited, no?

I could, indeed, in javascript block form submission of an additional field when another field has a certain value. This could work (though is somewhat cumbersome).

Is this what you are suggesting?

  Johan Wiegel (Admin) 17 January 12 / 07:58  
That is what I am suggesting.

after you submit the form the form is parsed again to validate the fields at that moment the conditional validator will work, not only in edit mode

  Babak Fakhamzadeh 27 January 12 / 12:00  
Got it! That would indeed work. Thanks!

  Top


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