Forums

How to make the form compatible with RTL & LTR

mhrde-boy 05 Apr, 2011
Hi all;

I am planing to make a bilingual site (Arabic + English).
I made many forms with CF component, and they worked great. But the direction of the form is static and not changing when I change the languages.

I edited the file (style1.css) to make the form in RTL direction, but now I want to make it LTR when I change the language to English.
There is a file named chronocontact.html.php contain the following code:
<?php if ($MyForm->formparams('LoadFiles') == 'Yes'){ ?>        	
			<?php if((!trim($MyForm->formrow->theme))||(trim($MyForm->formrow->theme) == 'default')){ ?>
                <link href="<?php echo $CF_PATH.'components/com_chronocontact/themes/default/css/'; ?>style1.css" rel="stylesheet" type="text/css" />
                <!--[if lt IE 6]><link href="<?php echo $CF_PATH.'components/com_chronocontact/themes/default/css/'; ?>style1-ie6.css" rel="stylesheet" type="text/css" /><![endif]-->
                <!--[if lt IE 7]><link href="<?php echo $CF_PATH.'components/com_chronocontact/themes/default/css/'; ?>style1-ie7.css" rel="stylesheet" type="text/css" /><![endif]-->


How can I add a code to call for a file named (style1_rtl.css) which contain the RTL style??

thank you in advance
GreyHead 06 Apr, 2011
Hi mhrde-boy,

I think that this should do what you need.
<?php
$lang =& JFactory::getLanguage();
if ( $lang->isRTL() ) {
  $stylesheet = 'style1_rtl.css';
} else {
  $stylesheet = 'style1.css';
}
$doc =& JFactory::getDocument();
if ($MyForm->formparams('LoadFiles') == 'Yes'){ 
  $style_path = $CF_PATH.'components/com_chronocontact/themes/default/css/';
  if((!trim($MyForm->formrow->theme))||(trim($MyForm->formrow->theme) == 'default')){
    $doc->addStyleSheet($style_path.$stylesheet);
?>
<!--[if lt IE 6]><link href="<?php echo $style_path; ?>style1-ie6.css" rel="stylesheet" type="text/css" /><![endif]-->
<!--[if lt IE 7]><link href="<?php echo $style_path; ?>style1-ie7.css" rel="stylesheet" type="text/css" /><![endif]-->
<?php
  }
}
?>

Bob
mhrde-boy 08 Apr, 2011
Sorry, but I'm not so good with PHP

I replaced the exact code that I mentioned in my first post with your one:
I noticed an error (the code color has gone in my notpad++ program) so I removed the closing ?> from your code >>> the color of the file codes came back but the form didn't work: I get a white page with no errors.

should I delete something? can you put the file with modifications here?

Thanks Bob
GreyHead 09 Apr, 2011
Hi mhrde-boy,

Sorry there was a mistake in my code - an extra <?php tag. I've now removed it from my earlier post. Please try again with the corrected version.

Bob
mhrde-boy 09 Apr, 2011
Sorry Bob;
I replaced the code in my first post with yours, Here is the result:
[attachment=1]01.PNG[/attachment]

as you see, there is an error, so I deleted:
      }
    }
    ?>


and this is what it looks like now:
[attachment=0]02.PNG[/attachment]

When I went to the front page, I used "Firebug" to see which file is controling the style:
the firebug indicates a file called style1_rtlcss NOT style1_rtl.css

Where is the problem??
Could you attach the file chronocontact.html.php after modifing it?

Thanks again Bob
regards
GreyHead 09 Apr, 2011
Hi mhrde-boy,

I missed some quotes '' in these lines :-(

if ( $lang->isRTL() ) {
  $stylesheet = 'style1_rtl.css';
} else {
  $stylesheet = 'style1.css';
}

Bob
mhrde-boy 09 Apr, 2011
Finally!

Thanks Bob, you are AMAZING :wink:

Since you support multilanguage forms, I suggest (in the coming release) to add this code to the file chronocontact.html.php and make style1.css & style1_rtl.css files, this will be a greate addition to RTL sites and make your component support both directions.
This will cost you nothing and will not chanage any thing in how your extention work!

Best Regards
and thanks again Bob
This topic is locked and no more replies can be posted.