close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Set a session from a submitted form

Thread began 9/03/2013 7:12 pm by mrs | Last modified 2/11/2014 4:07 pm by madahmani | 1184 views | 15 replies |

mrs

Set a session from a submitted form

I think I am being a bit thick here, but I can't for the life of me figure out how to set a session variable from a submitted form. Normally I set sessions with recordset info, and as I just want it stored for the session rather than in a DB, I can't get my head around it.

Basically, I am creating a simple select menu on one page that when submitted will be used on another page that the form posts to.

How do I do this?

Sign in to reply to this post

mrs

Aha... don't worry, I have just figured it out. I've even impressed myself in the course of doing so!

Sign in to reply to this post

madahmani

Can you please share with the rest of us how you managed to do this please ?
Many thanks.

Sign in to reply to this post

Jason ByrnesWebAssist

Data Bridge has a Server Behavior for setting a session variable.

open the server behaviors panel and click the plus button. Select WebAssist -> Cookies -> Set Session Value.

for the trigger, select any form post.

for the name type the name you wish to use for the session variable

For the value, click the lightning bolt icon and select the form element you wish to save.

Sign in to reply to this post

madahmani

Session not retained

Hi Jason,

Thank you for your reply. I am indeed aware of this function and already used it but without any success. The session is not being retained.

In my case, I have a form divided on two pages. step1.php and step2.php

On top of the first page I started the session handling:

<?php
if (!isset($_SESSION)) {
session_start();
}
?>

I have then applied the session value to all the form elements:

<?php
@session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$_SESSION["mem1_Title"] = "".((isset($_POST["mem1Title"]))?$_POST["mem1Title"]:"") ."";
}?>

For the second page I have again used sessions:

<?php
if (!isset($_SESSION)) {
session_start();
}
?>


But when I want to read the session value like this: <?php echo((isset($_SESSION["mem1_Title"]))?$_SESSION["mem1_Title"]:"") ?>

I get nothing, the session is empty.

Sign in to reply to this post

Jason ByrnesWebAssist

on the first page, what is the action of the form?

Does it post to itself?

or post to the second page?

if it posts to the second page, the code to set the session will need to be on that page.


remember, rule #1 when working with forms:

All form processing must occur on the forms action page.


In the future, though, if you asking about how to do something and you have already tried the correct method, include that information in the question.


your question really isn't:

How to store the form in a session, which is what you led off with, but rather:

I'm trying to store it in a session, but it doesn't work...

Sign in to reply to this post

madahmani

Hi Jason,

Well, I understand the confusion that happened by my question but that's because I asked you a new question on a thread that was meant for another issue.

At the beginning I wanted to know how "mrs" did it to store the session but then I found out by myself.

Then I wanted to share with you the issue I was facing when trying to use WebAssist's session registration.

Well, now after taking into consideration your note about having the form processing into the action page, everything went fine and I was able to display the session values.


Now, following this discussion, I would also like to point to your attention a little "bug" that I found while using CSS form builder.
Here is the situation:

I have a form, written, complete and well organized.
I wanted to use it with CSS Form Builder by binding its elements to be able to: apply validation, save values in sessions and keep the values persistent in the form fields.

The problem occurs after applying the CSS Form Builder and clicking the Finish button, all the "extra code" generated by DataBridge is writen inside the page except the code in the header that contains the includes like persist.php and the session storage.

I repeated the process many times and each time the code is not generated.

On the other hand, when I create a form from scratch using CSS Form Builder, all the code gets generated fine and all the assets related to the validation, session and values persistence are written succesfully.

If you want I can recreate the case again and send you screenshots.

Thank you.

Sign in to reply to this post

Jason ByrnesWebAssist

Well, CSS form builder is just that, A form Builder.

It is not intended for editing existing forms.

Where you have an existing form, you need to manually add the validation.


See this tutorial for details on adding validation to existing forms:
http://www.webassist.com/tutorials/Add-server-validation-to-your-web-forms

Sign in to reply to this post

madahmani

I totally understand that but not only the validation, nothing above the <html> tag is written.

Sign in to reply to this post

madahmani

Like these includes for examlpe:

<?php require_once("webassist/forms/persist.php"); ?>
<?php require_once("webassist/form_validations/wavt_scripts_php.php"); ?>
<?php require_once("webassist/form_validations/wavt_validatedform_php.php"); ?>

And all the rest of the PHP that should be written for the form.

Sign in to reply to this post
loading

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...