JavaScript Registered vs non-registered members

om omidhz 15 Feb, 2010
Hi,
I have a javascript code for my form which I want to edit secionts of it based on my user status. What I mean is:
If user is signed in Execute A
If user is Not signed in Execute B

How can I do this?
Thanks
Gr GreyHead 15 Feb, 2010
Hi omidhz,

Put the user->id (or user->guest) into a hidden field. Then you can check the value with your script.

Bob
om omidhz 15 Feb, 2010
Could you please explain how I can do this? I'm not really sure how to check the value?
Gr GreyHead 15 Feb, 2010
Hi omidhz,

In your form html you need to add this at the end
<?php
if ( !$mainframe->isSite() ) { return; }
$user = & JFactory ::getUser();
?>
<input type='hidden' name='user_id' value='<?php echo $user->id; ?>' />

Bob
om omidhz 16 Feb, 2010
Thank you for your quick reply. I will try this and get back to you. I think it should work just fine for what I need.
om omidhz 19 Feb, 2010
I have a small issue here. The above code is php so it loads with the form. My calculation is in javascript which loades before the form. What I need is to have a javascript if...else command.
if use is registered run A if not registered run B. How I can use the above code in javascript?
I really appreciate your support.
Gr GreyHead 19 Feb, 2010
Hi omidhz,

None of your scripts *should* run before the form loads; so add an id and check in the script for the value of the hidden field.
<input type='hidden' name='user_id' id='user_id' value='<?php echo $user->id; ?>' />
var user_id = $('user_id').value;

Bob
om omidhz 21 Feb, 2010
Great. It worked exactly the way I wanted to be. Thank you. You really provide excellent service and I'm really glad that I paid for the license and your product. GREAT JOB and keep up the GREAT work.
This topic is locked and no more replies can be posted.