Author Topic: Form fields + session variables  (Read 2398 times)

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
Form fields + session variables
« on: March 21, 2008, 09:53:55 PM »
In my form I check if a session variable isset, and if it is, I populate the field. (I do this to save the user from re-populating the form fields when they are taken to the validation page, then navigate back).

Scenario:
I input incorrect data on PAGE A, and am taken to the validation page. At this point the variables are stored in $_SESSION[].

I decide I no longer want to input the data anymore and navigate to another section of the site. I then decide to navigate back to PAGE A to see my previously incorrect data is still there.

What is the best way to handle this? (Note: The user is logged in using session variables)

Thanks


hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Form fields + session variables
« Reply #1 on: March 21, 2008, 11:24:36 PM »
How are you currently doing your validation? It's on a separate page? You could do the validation and redisplay the form page with error messages and the current values from the request. Then you wouldn't have to worry about storing them in the session and when they visit a new form it would be clean.

Are you using an MVC pattern?

You might also be able to get away with implementing a "new form" parameter that gets cleared when you navigate away.
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Form fields + session variables
« Reply #2 on: March 22, 2008, 08:49:31 AM »
I wouldn't use SESSION to store form validation data.  I'd use POST and your validation script should send them back to the form if it's wrong data.

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
Re: Form fields + session variables
« Reply #3 on: March 23, 2008, 11:12:39 AM »
>>How are you currently doing your validation? It's on a separate page?
Yes, JS errors are displayed on the current page, if it passes, it goes on to server side validation on a separate page.

>>Are you using an MVC pattern?
What is an MVC pattern?

>>I'd use POST and your validation script should send them back to the form if it's wrong data.
How would I send them back? I was trying to populate them with $_POST[], but that didnt seem to work.

//Edit: Should I put the variables into the URL and retrieve them via $_GET[]?

Thanks
« Last Edit: March 23, 2008, 07:21:36 PM by Canuck »

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions