Using PHP Include Method / CSS gets messed up.

mapme 01 Feb, 2012
Hi,
I am trying to display certain parts of a form only to a certain user.
I am using the following method, which works outside of the Chronoforms environment:


<?PHP  $user = JFactory::getUser(); ?>
<?php
if($user->username ='Brendan')
{
?>
<?php
include 'schemes/Brendan.php';
?>
<?php
}
?>


The related Brendan.php file is as follows:


<?php


    <select>
<option value="">Select Scheme...</option>
<option value="wex-1">Scheme1</option>
<option value="wex-2">Scheme2</option>
<option value="wex-3">Scheme3</option>
    </select>
     </div>
</div>

?>



The problem is that the layout/CSS gets messed up.
Is there a way of doing this correctly so that CSS is maintained?

Thanks,

Brendan
GreyHead 01 Feb, 2012
Hi mapme,

You've missed an = and been overrun by PHP tags :-(
<?php
$user = JFactory::getUser();
if ( $user->username == 'Brendan' ) {
  include 'schemes/Brendan.php';
}
?>

<select>
  <option value="">Select Scheme...</option>
  <option value="wex-1">Scheme1</option>
  <option value="wex-2">Scheme2</option>
  <option value="wex-3">Scheme3</option>
</select>

Including HTML in the middle of a PHP statement might not be what you want here though. Another version is
<?php
$user = JFactory::getUser();
if ($user->username == 'Brendan') {
  include 'schemes/Brendan.php';
}
// . . .
echo $select;
?>

<?php
$select = "<select>
  <option value=''>Select Scheme...</option>
  <option value='wex-1'>Scheme1</option>
  <option value='wex-2'>Scheme2</option>
  <option value='wex-3'>Scheme3</option>
</select>";
?>

Bob
mapme 01 Feb, 2012
Hi Bob,
Thanks so much for that!
Cheers.
Brendan
This topic is locked and no more replies can be posted.