joejac
Posts: 242
|
| Posted: 12/11/2007, 6:19 PM |
|
Hello.
I am trying to assign the security level to a javascript variable in order to provide the users with 2 different FCK editor Tool bar Set, depending on his security level. I get a Javascript syntax error, the php is not interpreted, I tried with echo and other ways but same problem. Can some body show me what am I doing wrong?
//Attach FCKeditor @29-DC7E2B92
var articulosresumen_FCK = new FCKeditor(this.getAttribute("id"));
var securitylevel = <?= CCGetGroupID() ?>;
//var securitylevel = <? CCGetGroupID() ?>; same problem
articulosresumen_FCK.BasePath = "/editor/";
if (securitylevel <2) {articulosresumen_FCK.ToolbarSet = "Default";}
else{articulosresumen_FCK.ToolbarSet = "Basic";}
articulosresumen_FCK.Height = "350";
articulosresumen_FCK.ReplaceTextarea();
//End Attach FCKeditor
Thanks a lot
joejac
|
 |
 |
datadoit
|
| Posted: 12/11/2007, 6:30 PM |
|
Can't do that, as far as I know. You could possibly send the security
group as an argument to the FCKeditor() class (?).
It may be easiest to simply create two text areas with the FCKeditor
attached to them, and hide one or the other via PHP based on your
security conditions.
|
|
|
 |
joejac
Posts: 242
|
| Posted: 12/11/2007, 6:45 PM |
|
Hello datadoit, thanks for your fast reply.
I tried what you said first, with panels, but because I have 2 TextAreas trying to update same database field, I lose what I have in the shown TextArea because the hidden one overwrites the field with nothing. It is frustrating I lost hours. Any other idea?
I remember years ago a friend of mine expert in javascript and php mixed php and javascript with a dependent listboxes solution and worked fine.
Regards
joejac
|
 |
 |
datadoit
|
| Posted: 12/11/2007, 7:26 PM |
|
joejac wrote:
> I tried what you said first, with panels, but because I have 2 TextAreas trying
> to update same database field, I lose what I have in the shown TextArea because
> the hidden one overwrites the field with nothing. It is frustrating I lost
> hours. Any other idea?
>
> ---------------------------------------
Yes, you'll have to work around that. Perhaps put in a hidden field on
your form that is bound to the database field. Don't bind your text
areas to the field. Then, in OnValidate for the form, test the
visibility condition for each text area, and the one that isn't hidden,
copy it's value to your hidden field.
Ex:
if ($Container->textarea1->Visible == true) {
$Container->Hidden_field->SetValue($Container->textarea1->GetValue());
}
|
|
|
 |
datadoit
|
| Posted: 12/11/2007, 7:33 PM |
|
joejac wrote:
> Hello.
>
> I am trying to assign the security level to a javascript variable in order to
> provide the users with 2 different FCK editor Tool bar Set, depending on his
> security level. I get a Javascript syntax error, the php is not interpreted, I
> tried with echo and other ways but same problem. Can some body show me what am I
> doing wrong?
>
> //Attach FCKeditor @29-DC7E2B92
> var articulosresumen_FCK = new FCKeditor(this.getAttribute("id"));
> var securitylevel = <?= CCGetGroupID() ?>;
> //var securitylevel = <? CCGetGroupID() ?>; same problem
> articulosresumen_FCK.BasePath = "/editor/";
> if (securitylevel <2) {articulosresumen_FCK.ToolbarSet = "Default";}
> else{articulosresumen_FCK.ToolbarSet = "Basic";}
> articulosresumen_FCK.Height = "350";
> articulosresumen_FCK.ReplaceTextarea();
> //End Attach FCKeditor
>
> Thanks a lot
> joejac
> ---------------------------------------
I did notice that your <? CCGetGroupID() ?> does not contain an inner
simicolon. Should be: <? CCGetGroupID(); ?>
You have to end your PHP command line. Dunno if this is why it isn't
working or not. I have my doubts if doing this will work, but am
certainly curious.
Something else you could try is putting a hidden field at the top of
your form, and assigning it's default value to CCGetGroupID(). Then you
could test it's value in your javascript:
var security_level = document.forms["YourForm"].YourHiddenField.value;
|
|
|
 |
CodeChargenewbie
Posts: 114
|
| Posted: 12/12/2007, 1:53 PM |
|
Just my two cents here.
You can't execute php code in HTML view. Codecharge doesn't work that way. It'll just print out whatever you type. In order to mix javascript and php, you have to go into the custom code. I make a label with content type HTML, write the code as a string, and then pass the string to the label.
something like this:
$num = 5;
$Container->Control->SetValue("<script='javascript' type='text/javascript'> var num = " . $num . ";</script>");
FYI, you cannot do the opposite and set javascript values to php variables in this method because the process is server-side code then client-side. Now you can pass form values to javascript, but straight php has to be done in Code view with Content type set as html.
|
 |
 |
joejac
Posts: 242
|
| Posted: 12/12/2007, 3:34 PM |
|
Thanks to everybody for your nice help.
I used all your ideas plus the following topic: http://forums.codecharge.com/posts.php?post_id=86581&
And I did the following:
1.- Created a Text Box at the end of the form
2.- In Before Show Event of the Text Box I entered the following custom code:
$articulos->TextBox1->SetValue(CCGetGroupID());
3.- In the HTML view I changed the FCK javascript as follows:
//Attach FCKeditor @29-DC7E2B92
var articulosresumen_FCK = new FCKeditor(this.getAttribute("id"));
var securitylevel = {TextBox1};
articulosresumen_FCK.BasePath = "/editor/";
if (securitylevel <2) {articulosresumen_FCK.ToolbarSet = "Default";}
else{articulosresumen_FCK.ToolbarSet = "Basic";}
articulosresumen_FCK.Height = "350";
articulosresumen_FCK.ReplaceTextarea();
//End Attach FCKeditor
4.- And It "works" BUT only works if I have the Visible property for the Text Box in "Yes" otherwise there is no value returned for {TextBox1}
I do not want to have this TextBox1 visible, can some body Help with this? any Idea?
Thanks a lot to everybody.
Regards
joejac
|
 |
 |
datadoit
|
| Posted: 12/12/2007, 5:08 PM |
|
> I do not want to have this TextBox1 visible, can some body Help with this? any
> Idea?
>
> Thanks a lot to everybody.
> Regards
> joejac
> ---------------------------------------
Make the text box a hidden field.
|
|
|
 |
joejac
Posts: 242
|
| Posted: 12/12/2007, 6:30 PM |
|
Thanks a lot datadoit, hidden field solved the problem.
Very nice and helpful people in this forum.
Best regards to all.
joejac
|
 |
 |
|