If a registered user is filling in a form i don't want to collect information about him that we already know, such as name, surname, address, etc. But if a new user fills out the form, then I want that information collected. Is there a way to do that?
This example assumes that you have two sections to your form. The first section (tagged as Section 1 in the image below) would be presented to users who are not logged in, but would be hidden for users who ARE logged in. Section 2 would be displayed to all users, logged in or not.
For the purpose of this example, in the NAME field (underneath the label field in each section's properties), let's name the sections as follows:
Section 1 name: section1
Section 2 name: section2
All of the following code assumes that you are using these two section names!!
Go to your form's properties > Advanced Tab > and provide a dummy visibility rule to initialize the JS library. This dummy could look like this:
turn on element mydummy if yourdummy is something
Go to your form's properties > Advanced Tab > More Options and click on the SCRIPTS tab.
In the Initialization Script section, click on the CUSTOM radio button. Then paste in the code below:
function ff_FORMNAME_init() // remember to replace FORMNAME with the real name of your form { <?php if( JFactory::getUser()->get('id',0) > 0 ) { echo " function mytoggler() { bfToggleFields('off', 'section', 'section1', bfDeactivateField); bfToggleFields('on', 'section', 'section2', bfDeactivateField); } "; } else { echo " function mytoggler() { bfToggleFields('on', 'section', 'section1', bfDeactivateField); bfToggleFields('on', 'section', 'section2', bfDeactivateField); } "; } ?> } // ff_FORMNAME_init
Next, go to the FORM PIECES tab. In the AFTER FORM section, click on the CUSTOM radio button. In the text area that opens, enter the following code:
return ' <script> JQuery(document).ready(function() { mytoggler(); }); </script> ';
Now click on the SAVE icon in the lower right-hand corner of the screen to save the script and form piece changes that you made. Once back on the form properties page, click on the SAVE icon in the upper right-hand corner of the screen to save the form itself.