tags:

views:

122

answers:

2

Given a php form that submits to it’self, via <?php echo $_SERVER[‘PHP_SELF’];?>

And the same form with some html and one submit button

<label for="submit">Submit</label>
<input id="submit" type="submit" value="Submit Info:" /><br />

How do I set it up, such that when the user has finished inputting all the relevant information on the form(one, form.php), without any errors, the session is destroyed, after pressing the submit button.

I know this starts a session:

<?php session_start() ?>

At the top of form.

And this destroys the session variables

session_destroy();

Would I have to do something like this:

$_SESSION[‘submit’] = ‘submit’;

I am trying to avoid creating sessions for each variable on my form, for example,

name

age

sex

It sounds like it would be a lot of work to create sessions for each and every variable on a given form, that’s why I am here seeking answers, in the meantime I will read more on sessions, thank you for not flaming the newb.

+1  A: 

Sessions and forms are two different things. I don't quite get what you want to, first you speak of destroying a session, which is done, as you said, with session_destroy(); - Then you talk about variables of your form...

Submitted forms store their data in a $_GET or $_POST-variable, not in the $_SESSION - If you don't want that, what's the point of the form anyway?

See, what should happen if the user clicks submit? Form is submitted to the same page, so far I get that.

But why do you think you create a $_SESSION for every field in the form?

ApoY2k
I just thought there was a more elegant way of doing it, as pointed out by Ben Fransen.I guess next time I will keep my questions short:"How do I set it up, such that when the user has finished inputting all the relevant information on the form(one, form.php), without any errors, the session is destroyed, after pressing the submit button."So I guess I am on my own, I thought I could destroy my own sessions in the pursuit of learning?
Newb
+2  A: 

Why exactly are you using sessions? If it is for formprocessing you should use POST or alternativly GET. SESSIONS are a great way to store configurations, accesslevel settings, shoppingcarts etc.

BTW, if you are going to use sessions, you can also just create one session and store all sessiondata in an array, then submit that array to a $_SESSION["mySession"].

E.g. if you have a maximum amount of weblogs to show on a page this could be retrieved like $_SESSION["mySession"]["maximum_amount_of_weblogs_per_page"].

Then ofcourse you have to add the array("maximum_amount_of_weblogs_per_page" => 10); to $_SESSION["mySession"].

Hope it's usefull to you.

Ben Fransen
Thank you.BTW, if you are going to use sessions, you can also just create one session and store all sessiondata in an array, then submit that array to a $_SESSION["mySession"]., again thank you.
Newb