php - Send variable to the user profile in Drupal 6

455

I'am developing a module for Drupal which provides a login form and after submission user cURL to login in with those credentials on another website.

If all goes well, the module redirects the user to their profile and should present the information cURL fetched. This is where things go wrong.

What I'm trying to do is get the$account variable through the username. This is all in themodule_name_form_submit function:

$account = user_load(array('name' => check_plain($user)));

And then append the data I want to display to it:

$account->content['module_name'] = array(
    '#title' => t('Module Title'),
    '#values' => get_info()
    );

If I do aprint_r before the redirect, sure enough, the data is there as it should. But after the redirect:

$form_state['redirect'] = "users/{$user}";

I no longer have access to that same data. So the question is, how can I set that variable in a permanent way and access it after the redirect in the user profile page? (I'm trying to avoid sessions).

Thanks in advance :-)

964

Answer

Solution:

How about use variable_set($name, $value); According to your question:

variable_set('module_name_variable', $account);

When you need to access the data use variable_get($name, $default); As per your question:

variable_get('module_name_variable');

please let me know if it works for you.

Thanks

215

Answer

Solution:

Maybe you could use the value form element to add the user value to your form.

$form['userdata'] = array('#type' => 'value', 
                     '#value' => $user_load(array('name' => check_plain($user)));

I think this may do what you are looking for in a 'drupalish' way.

Hope it helps, good-luck!

People are also looking for solutions to the problem: php - Doctrine 1.2 calculating the sum of oneToMany relations with DQL

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.