Jump to content

[SOLVED] Post and Session Issues


dfowler

Recommended Posts

Hey guys, I have a form that goes to a confirm page.  The confirm page displays the data from the form and also loads some session variables (checks whether the person who filled out the form is logged in or not).  I have a link set up using

<a href="javascript:history.go(-1)" >

so people can go back and make any corrections if they typed in something wrong.  When they click the link it prompts to repost data, however, none of the information is in the form.  They have to refill everything.

 

How do I get the information to repost?

Link to comment
Share on other sites

by default the forms do not keep data in them. I have had issues with this in the past. Sometimes they do and sometimes they don't. Can't really give you a reason why, on the other hand to get back to your question, once the form is submitted you can put those values into a session in case they click back. and have the form look for the session values.

 

Ray

 

Link to comment
Share on other sites

by default the forms do not keep data in them. I have had issues with this in the past. Sometimes they do and sometimes they don't. Can't really give you a reason why, on the other hand to get back to your question, once the form is submitted you can put those values into a session in case they click back. and have the form look for the session values.

 

Ray

 

 

Yeah, I have a form on another page that doesn't involve sessions at all, when you click the back link all the text is still in the form.  It is only for the form with the sessions.  I'll have to think of a way to do this as the form is a dynamic form.

Link to comment
Share on other sites

On the form page you can do something like this.

 

<input type=text name=fieldname value="<? if(isset($_SESSION['form']['fieldname'])){echo $_SESSION['form']['fieldname']; } else { echo ""; } ?>" />

 

That way when you first fill out the form the values will be blank, once you submit the form you can store the value and when you click back the value will now be set.

 

Ray

Link to comment
Share on other sites

On the form page you can do something like this.

 

<input type=text name=fieldname value="<? if(isset($_SESSION['form']['fieldname'])){echo $_SESSION['form']['fieldname']; } else { echo ""; } ?>" />

 

That way when you first fill out the form the values will be blank, once you submit the form you can store the value and when you click back the value will now be set.

 

Ray

 

don't I have to register the session at some point?

Link to comment
Share on other sites

Here is the main code for the form

 

<?php foreach($items[$c['id']] as $i) { ?>
<input type="text" name="qty[<?php echo $i['id']; ?>]" size="3" />
  			</div>
		<?php
  				if ($i['options'] == '1') {
		?>
  					<div id="itemOptions" style="display:block;">
    						<span class="small-text"><i><?php echo $i['options_prompt']; ?></i></span><br />
					<textarea class="view-options" name="options[<?php echo $i['id']; ?>]"></textarea>
  					</div>

Link to comment
Share on other sites

Here is the main code for the form

 

<?php foreach($items[$c['id']] as $i) { ?>
<input type="text" name="qty[<?php echo $i['id']; ?>]" size="3" />
  			</div>
		<?php
  				if ($i['options'] == '1') {
		?>
  					<div id="itemOptions" style="display:block;">
    						<span class="small-text"><i><?php echo $i['options_prompt']; ?></i></span><br />
					<textarea class="view-options" name="options[<?php echo $i['id']; ?>]"></textarea>
  					</div>

 

Is it possible to do something like this?

<?php if(isset($_SESSION['qty.$i['id']'])){echo $_SESSION['qty.$i['id']']; } else { echo ""; } ?>

Link to comment
Share on other sites

Ok here is where I am at now.  Here is the code for the form:

<?php foreach($items[$c['id']] as $i) { ?>
<input type="text" name="qty[<?php echo $i['id']; ?>]" size="3" value="<?php if(isset($_SESSION['qty['.$i['id'].']'])){echo $_SESSION['qty['.$i['id'].']']; } else { echo ""; } ?>" />
  			</div>
		<?php
  				if ($i['options'] == '1') {
		?>
  					<div id="itemOptions" style="display:block;">
    						<span class="small-text"><i><?php echo $i['options_prompt']; ?></i></span><br />
					<textarea class="view-options" name="options[<?php echo $i['id']; ?>]"><?php if(isset($_SESSION['options['.$i['id'].']'])){echo $_SESSION['options['.$i['id'].']']; } else { echo ""; } ?></textarea>
  					</div>

 

 

Then here is my code on the next page where I am displaying the data from the form and registering the session:

foreach($_POST['qty'] as $k => $v) {
$query  = "SELECT * FROM items where id='$k'";
	$result = mysql_query($query);
	$qty = $_POST['qty'][$k];
	$options = $_POST['options'][$k];

	session_register('qty[$k]');
        	$_SESSION['qty[$k]'] = $qty;
        	session_register('options[$k]');
        	$_SESSION['options[$k]'] = $options;
}

 

It still isn't working though.  I know I'm not doing it right, but I'm starting to get pretty lost.

Link to comment
Share on other sites

I know I keep answering myself.  However, I figure as I post progress people can help me out.  Here is where I stand now.  I think I've made a little head way as the $_SESSION is working on the confirm page.

 

foreach($_POST['qty'] as $k => $v) {
$query  = "SELECT * FROM items where id='$k'";
	$result = mysql_query($query);
	$qty = $_POST['qty'][$k];
	$options = $_POST['options'][$k];

	session_register('qty[$k]');
        	$_SESSION['qty'][$k] = $qty;
        	session_register('options[$k]');
        	$_SESSION['options'][$k] = $options;
}

 

I think the problem now is that when users click this:

<a href="javascript:history.go(-1)">Here</a>

 

It is going back therefore the sessions are registering?  I could be wrong of course (and I know I probably am).  I feel that I am really close with this.  Here is the code for the initial form now:

 

<?php foreach($items[$c['id']] as $i) { ?>
<input type="text" name="qty[<?php echo $i['id']; ?>]" size="3" value="<?php if(!$_SESSION['qty'].'['.$i['id'].']'){ echo ""; } else { echo $_SESSION['qty'].'['.$i['id'].']'; } ?>" />
  			</div>
		<?php
  				if ($i['options'] == '1') {
		?>
  					<div id="itemOptions" style="display:block;">
    						<span class="small-text"><i><?php echo $i['options_prompt']; ?></i></span><br />
					<textarea class="view-options" name="options[<?php echo $i['id']; ?>]"><?php if(!$_SESSION['options'].'['.$i['id'].']'){ echo ""; } else { echo $_SESSION['options'].'['.$i['id'].']'; } ?></textarea>
  					</div>

 

 

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.