Jump to content

Multi -entrance form handling


YigalB

Recommended Posts

I am totally newbie, doing my first project, after reading a PHP book.

The page I am trying to build is like a quiz: displays a simple form,  get answers and display "Good/bad answer".

This is easy, but the form needs to continue based on the first answers, something like 5-6 more steps. Each step depends on the data from the previous steps.

 

Can I still use the approach like the example below?

 

What happens to the variables when the PHP script is re-visited? can I assume their values are still valid?

 

// The example I thought I will use:

<?php

// if form not yet submitted, display form

if (!isset($_POST['submit'])) {

?>

<form ..................................................

</form>

<?php

// if form submitted

// process form input

} else {

.....

$num = $_POST['num'];

..........

} else {

echo ' my message ............................

}

?>

Link to comment
Share on other sites

if you are moving from page to page AND want to retain variable values you could (1) use SESSIONS to hold the values, (2) store the values in a database table [deleting the records after an appropriate amount of time].

I read about SESSIONS and it looks the right solution for me. Thank you. One thing bothers me:

What happens if 2 or more people work on the same web site at the same time? Both sessions will use the same session variable? or perhaps the answer is that each user gets his virtual work place, and so his variables are kept his. In this case - how can the PHP tell which variables refer to which user when re-visit occurs?

 

Link to comment
Share on other sites

Sessions are per visitor. Each visitor gets a separate session id and a corresponding session data file on the server where the session variables are saved when your script ends.

 

When that visitor requests a page, the session id is set from the browser to the server and the server reloads the correct session data into the $_SESSION variables for that visitor.

Link to comment
Share on other sites

So does it mean that every browser window opened is consider another session ID? i.e. if I open 5 different browser pages to the same site I occupy 5 different session IDs and they are considered totally different as if 5 different users were using this page same time?

 

Also, does it mean the data of the session disappears when ii close the window? If so, what would you recommend me to use if I wanted to log the data? E.g. user name, the quiz difficulty and the result?

Link to comment
Share on other sites

Assume the following scenario:

The user opens a Chrome browser and goes to www.mysite.com. He is alone on that server, so no problem - start working on that form.

While in the form, the user opens another tab on the same chrome browser, typing also www.mysite.com.

 

There are two possible options:

1- This tab will get different working environment, so the user could fill a parallel form

2- The server's PHP program will check the variable and sense already in use. In this case, it will execute the "what if i already filled the form", getting to the same place as the first tab. This doesn't make sense to me, as now we will have two similar sessions.

 

What did I miss?

 

Link to comment
Share on other sites

What exact problem are you trying to solve?

 

Unless you do some unusual session id handling yourself, when you have multiple-tabs and/or multiple-instances of ONE browser open at the same time, there will be one single session id for any one URL and there will only be one set of corresponding session variables on the server. If you have multiple copies of the same form open, the last form submitted would replace any data previously submitted in one of the other tabs/instances of that browser unless you do something in your code to detect and ignore the multiple submissions.

Link to comment
Share on other sites

Is user required to log in?

At this stage - no, mainly because I don;t know yet how to handle the data base of the log in.

At first stage, I will just ask user to fill name, and the data will be emailed to me for analysis.

 

Later on, I will have to handle the login as well. As newbie, the site content is a big challenge already...

 

Why does it matter?

Link to comment
Share on other sites

Assume the following scenario:

The user opens a Chrome browser and goes to www.mysite.com. He is alone on that server, so no problem - start working on that form.

While in the form, the user opens another tab on the same chrome browser, typing also www.mysite.com.

 

...

 

This doesn't make sense to me, as now we will have two similar sessions.

 

What did I miss?

 

You missed that there is still only one session. One session per browser. Not one session per browser tab. Not one session per browser window. One session per browser.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.