Jump to content

[SOLVED] Help with keeping form fields populated using sessions


CodeMama

Recommended Posts

I found a couple examples and have tried and they all seem to be based around this but it doesn't work anyone see my error?

 

  <tr>
                                <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td>
                                <td width="80%" height="30"><input name="searchname" type="text" size="30"
                                <?php
                                if(isset($_SESSION['searchname']))
                                {
                                  echo " value='" . $_SESSION['searchname'] . " ['searchname'] '";
                                }
                                  ?>
                                  >
                                </td>
                                
                                                                
                              </tr>

 

The session_start() is at the top of my page along with checking for the sessions.... help help

Link to comment
Share on other sites

You're wanting it to... like for example if searchname is "CodeMama"

 

you want it to say this?  value='CodeMama ['searchname'] '

 

because thats what you have set... and actually that will create a problem because you have single quotes within single quotes.

 

I would assume you just want value='CodeMama'... which means you just do this:

 

echo " value='" . $_SESSION['searchname'] ."'";

Link to comment
Share on other sites

well I added it and now when I reload the page it wouldn't release the sessions, so I put this

    // Check if there was an empty search sent
							    if(isset($_SESSION['noVarsSent']))
							    {
							      echo "<p><b>No values were submitted for the search.</b></p>";
							      // Unset it so a reload of page doesn't redisplay the error
							      unset($_SESSION['noVarsSent']);
							      unset($_SESSION['results']);
							      unset($_SESSION['searchname']);
							      unset($_SESSION['address']);
							      unset($_SESSION['bmonth']); 
							      unset($_SESSION['bday']); 
							      unset($_SESSION['byear']); 
							      unset($_SESSION['emonth']); 
							      unset($_SESSION['eday']);
							      unset($_SESSION['eyear']); 

							      unset($_SESSION['totalNumberOfRestaurants']);
							   
							     
							    }else{
							    $_SESSION['searchname'] = $_POST;
							    $_SESSION['address'] = $_POST;
							    $_SESSION['bmonth'] = $_POST;
							    $_SESSION['bday'] = $_POST;
							    $_SESSION['byear'] = $_POST;
							    $_SESSION['emonth'] = $_POST;
							    $_SESSION['eday'] = $_POST;
							    $_SESSION['eyear'] = $_POST;

							    }
							    


							  ?>

 

now when I reload the page it says "Array" in the search text boxes?

Link to comment
Share on other sites

$_SESSION['searchname'] = $_POST;

 

unless it's something about php that i don't know about, that wont do anything...try

 

$_SESSION['searchname'] = $_POST['searchname'];

 

========

 

also not sure how this is getting set?

 

if(isset($_SESSION['noVarsSent']))

 

I'm also unsure of what the bigger picture looks like in this situation so maybe thats why I'm confused

Link to comment
Share on other sites

wow this is getting tricky...I put the $_POST =['blah'] in there and it just gave me a bunch of undefined variable errors, so I put it like this

which got rid of the errors but...doesn't keep the values

  <tr>
						    <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td>
						    <td width="80%" height="30"><input name="searchname" type="text" size="30"
						    <?php
						    if(isset($_SESSION['searchname']))
						    {
						      echo " value='" .   $_SESSION['searchname'] = $_POST['searchname'] ."'";
						    }
						      ?>
						      >
						    </td>
						    
						    							    
						  </tr>

Link to comment
Share on other sites

your code is saying...

 

if

$_SESSION['searchname']

is already set, set it... otherwise leave it unset ?

 

 

does your form action load this page that you are taking the code from? if so you could just switch

 

if(isset($_SESSION['searchname']))

with

if(isset($_POST['searchname']))

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.