TOA Posted July 12, 2011 Share Posted July 12, 2011 Hi. I need some help. I don't know if I've just been staring at this for too long or what, but I can't figure out how to make the form below sticky (and by that I mean the values stay if there is an error and redirect). I get lost in all the arrays Here's the code for my form: $num = intval($_SESSION['num']); if (isset($_SESSION['PlanError'])) { echo "$_SESSION[PlanError]<br />"; } echo "<form action='' method='POST'>"; for ($i=1; $i < $num + 1; $i++) { <table> <tr><th>General Plan Info</th><th>Supplemental Benefits</th></tr> <tr><td class="half">Plan Name <input type="text" name="<?php echo 'P['.$i.'][name]';?>" value="<?php checkArraySticky('1', 'name'); ?>" /><br /> </table> } echo '<input type="submit" name="continue" value=" Continue " class="button" /><input type="submit" name="save" value=" Save and finish later " class="button" />'; echo "</form>"; There's a few more fields in there, but they're not needed for the example, they all work the same way. So as you can see, the user post's a number from another script and this takes it and shows that many versions of it. So all the inputs are arrays like $P[1][name] for example (meaning plan 1 name) I just can't figure out how to make it sticky. I tried throwing everything in a session but can't get it to work. Here's what I tried to make it sticky: function checkArraySticky($num, $value) { if (isset($_SESSION['userVals']['P'][$num][$value])) { echo $_SESSION['userVals']['P'][$num][$value]; } } Any suggestions? *** EDIT *** Nevermind, that worked, I just wasn't calling the function right Quote Link to comment https://forums.phpfreaks.com/topic/241836-help-making-a-form-sticky/ Share on other sites More sharing options...
djlee Posted July 12, 2011 Share Posted July 12, 2011 Where is uservals being set ? Quote Link to comment https://forums.phpfreaks.com/topic/241836-help-making-a-form-sticky/#findComment-1241943 Share on other sites More sharing options...
TOA Posted July 12, 2011 Author Share Posted July 12, 2011 Where is uservals being set ? Right before all that. It just takes the posted values and makes userVals out of it. I got it though, you replied just as I figured it out. Thanks for your response Quote Link to comment https://forums.phpfreaks.com/topic/241836-help-making-a-form-sticky/#findComment-1241946 Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 holy multi-dimensional array batman! Quote Link to comment https://forums.phpfreaks.com/topic/241836-help-making-a-form-sticky/#findComment-1241949 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.