dfowler Posted January 25, 2008 Share Posted January 25, 2008 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? Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2008 Share Posted January 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 25, 2008 Author Share Posted January 25, 2008 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. Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2008 Share Posted January 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 25, 2008 Author Share Posted January 25, 2008 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? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 You need session_start() at the top of each page then a $_SESSION variable to put it in. Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 25, 2008 Author Share Posted January 25, 2008 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> Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 28, 2008 Author Share Posted January 28, 2008 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 ""; } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted January 28, 2008 Share Posted January 28, 2008 Multi arrays are in this format array[1][2][3] Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 28, 2008 Author Share Posted January 28, 2008 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. Quote Link to comment Share on other sites More sharing options...
dfowler Posted January 28, 2008 Author Share Posted January 28, 2008 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.