By SmokOO on
Hi!
I'm still a newbie in Drupal. Recently I started using form API and I've encoutered a little problem. In my form I need to know who is filling it. I tried to use global $user but inside form it is invisible. Tried to surf the net for solution but came up with nothing (or I just missed it not knowing I have found it :P ) Thx for any advice!
Comments
The global $user variable should work.
The global $user variable should work, take a look at this example, It's tested and it's working:
Tried similar thing before
Tried similar thing before but #type was 'hidden' ... and that field is still empty even if I changed to 'textfield'. #value or #default_value also makes no diffirence. I checked query statement many times and even rewrote it. All data except 'user' goes to data base.
Hi, you need to first declare
Hi,
you need to first declare global $user, which will give you a user object, in order to get user id use $user->uid .
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
I've done that before :) and
I've done that before :) and outside $form this variable is visible... inside not :/
So the code is like that
So the code is like that (short version):
If you want to use $user
If you want to use $user inside sprzet_form($form_state), you need to write global $user inside the function ie. function sprzet_form($form_state){
global $user;
...
}
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
Sagar is right, in the #2
Sagar is right, in the #2 code example you see the
global $user;statement inside the form callback.And now it works :D Big THX
And now it works :D Big THX everyone!