Skip Navigation

[Resolved] How to store field value in a session

This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.15 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by salimA 3 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#2124333

Hi,

I would like to store user email in a session to pass it on to another page.

I have added the below code in the toolset custom code.

session_start();
$_SESSION['email']= 'user_email';

But it is not working. we got 'user_email' on the second page instead of the email value. I have added 'wpcf-' also before the field name but still, the value doesn't retrived.

#2124427

Hello and thank you for contacting Toolset support.

Well, first of all, you need the user ID. If you are looking for the current user ID, you can get it with:

$user_id = get_current_user_id();

https://developer.wordpress.org/reference/functions/get_current_user_id/

Then you can get the user's email with the following code:

$user_info = get_userdata( $user_id );
$user_email = $user_info->user_email;

Please note that this is a general PHP/WordPress development question. It has nothing to do with Toolset and is therefore considered custom code. Custom code is out of the scope of this support forum. Consider hiring a developer or seeking support in a general support forum such as StackExchange or StackOverflow.

#2127579

Thank you the code worked with the session. My issue is resolved now.