This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
$_SESSION['form_data'] variables not working immediately
Started 14 years ago by msfbiz | 3 posts |
-
I have a form that leads to a success page that uses $_SESSION['form_data'] variables to populate the success page.
E.g.
<?php
session_start();
$name = $_SESSION['form_data']['element_1_2'];
echo "Welcome " . $name;
?>But it doesn't work form the start. The success page doesn't show any of the $_SESSION['form_data'] variables.
However, if I hit the back button and resubmit the form data then the success page is populated correctly.
Please help resolve this issue.
Here's the code I have for the php-functions.php file:
//if there is any error message or elements, send false as status
if(empty($error_elements) && empty($process_result['custom_error'])){
$process_result['status'] = true;
//Store form variables in session variables
$_SESSION['is_valid_user'] = true;
$_SESSION['form_data'] = $table_data;
$_SESSION['form_data']['id'] = $record_insert_id;//if 'form review' enabled, send review_id
if(!empty($form_review)){
$process_result['review_id'] = $record_insert_id;
}
}else{
$process_result['status'] = false;
}return $process_result;
}I can privately email my form and success pages with code and links if needed.
Thanks!
MikePosted 14 years ago # -
Ok, I just solved it.
What was missing was the
session_start();
On the form page as well. I had it on the success page only.
So to summarize, if you need to retrieve data on your success page through session variables, you need to put the
session_start();
PHP statement on BOTH your form and success page.
Mike
Posted 14 years ago # -
Thanks for sharing the solution Mike.
session_start() is indeed needed for all pages which uses session variables.
MachForm Founder
Posted 14 years ago #
Reply
You must log in to post.