This topic is locked

How to show / hide sections dynamically

3/4/2011 5:08:51 PM
PHPRunner Tips and Tricks
F
FunkDaddy author

So, you want to hide a section (and all its fields within it) dynamically based on a PHP session variable?
Here's how:

  1. In Visual Editor find the control where the section is located (click on the foldable section), then switch to HTML view and give the <tr> element that is holding that control an ID. Ex:



<TR id=mbr_custom_section>

<TD style="WIDTH: 428px" class="es editshade_b" colSpan=2>

{$Section Custom_Fields1}

</TD>

</TR>


2. Switch back to regular view in visual editor and add a php snipper anywhere on the page. In that snippet add code that will dictate whether the the folding section show display or not. Ex:

if(

$_SESSION["Show_Households_CF1"] == 1 OR

$_SESSION["Show_Households_CF2"] == 1 OR

$_SESSION["Show_Households_CF3"] == 1 OR

$_SESSION["Show_Households_CF4"] == 1 OR

$_SESSION["Show_Households_CF5"] == 1

){

echo "<script language=\"JavaScript\"> var DisplayCustomTab = 1; </script>";

} else {

echo "<script language=\"JavaScript\"> var DisplayCustomTab = 0; </script>";

}


Notice that we are simply using some type of logic that will write to the page some javascript that we can then use later with the "JavaScript OnLoad event" to hide/show the section. We are writing to the page, however, since its encapsulated as javascript it won't actually print on the page... we're simply embedding a var on the page that can be used by onload event.
3. Now in your Javascript OnLoad event add the following to hide your folding section.



if(DisplayCustomTab == 0){

document.getElementById("mbr_custom_section").style.display="none";

}


4. Done!
OK.... by the way.. on the same day I implemented this solution, I incidentally came across the newly updated 5.3 online manual where it gives you an alternative for accomplishing the same thing. So take a look at the following two links:
http://xlinesoft.com/phprunner/docs/how_to_access_php_variables.htm
http://xlinesoft.com/phprunner/docs/how_to_work_with_foldable_section.htm
Hope this helps!
Cheers,