close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Session Variables Nightmare

Thread began 11/18/2010 11:15 am by Daryl | Last modified 11/22/2010 9:22 am by Jason Byrnes | 1272 views | 3 replies |

DarylBeta Tester

Session Variables Nightmare

I am having a nightmare with session variables (again!)

I have tried using the native Dreamweaver Session Variable options to set a form field as a session variable and then on the next page to display it, with no luck.

I have also tried the ecart set session value also which I sometimes get to work.

I have created a single element form like this (using the ecart behaviour);

<?php
if (!session_id()) session_start();
if(($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) {
$_SESSION["sessiontest"] = "".((isset($_POST["sessiontest"]))?$_POST["sessiontest"]:"") ."";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body><form action="thankyou_pdf.php" method="post">
<p>
<input name="sessiontest" type="text" />
</p>
<p>
<input type="submit" name="test" id="test" value="Test" />
</p>
</form>
</body>
</html>



And then try and display it here;

<?php
if (!isset($_SESSION)) {
session_start();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php echo $_SESSION['sessiontest']; ?>
</body>
</html>



But I either get a blank page or a value that I had created in the form earlier in the day.

Can someone please tell me how to set a session variable from a form element using either a DW or Webassist behaviour and then show it on the next page?

Thanks in advance

Sign in to reply to this post

Jason ByrnesWebAssist

is the form page named thankyou_pdf.php? or is thankyou_pdf.php the second page?


I ask this because the forms action is set to post to thankyou_pdf.php:
<form action="thankyou_pdf.php" method="post">


this is an important detail to note because all for processing must be performed on the forms action page.


you have the set session value code on the same page as the form, this will only work if the form is set to post to the same page that contains the form.

If the form is set to post to another page, the set session value code needs to be on that other page.

another important detail to note is the trigger. you have selected to use the Currant Page Submit trigger.

this trigger cannot be used if the form is set to post to another page.

Finally, make sure that all of your form elements have a values attribute, your text field is missing this:
<input name="sessiontest" type="text" />

some browsers will not post a form elements value if there is no value attribute:
<input name="sessiontest" type="text" value="" />

Sign in to reply to this post

DarylBeta Tester

Hi Jason

I have got something to work now.

I used ecart to set a session on the form page, made the next page the form action, then cut the ecart code from the first page and pasted into the top of the second page, which seems to work.

Is this right?

The reason why I used page submit as a trigger was that I found if button pressed was used, in IE it sometimes doesn't recognise it, but with page submit it did.

Sign in to reply to this post

Jason ByrnesWebAssist

you don't need to cut and paste the code.


if you have the form posting to another page, follow these steps:

On the action page, go to the bindings panel and click the plus button, select Form Data. Click the folder icon in the form data window and select your form page. This will add dynamic data bindings for the form to the forms action page.

Now on the action page, you can add the server behaviors using the form data bindings.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...